Ваш фрагмент выглядит хорошо, однако, когда вы хотите плавного поворота камеры, можно настроить, чтобы значения сглаживались при увеличении или уменьшении до новой позиции мыши.
Это то, что делает Unity.просто во время перевода мыши и ее свойств преобразования, все, что вам нужно сделать, это Slerp значений последней позиции и новой позиции мыши, скорректированной с учетом скорости перемещения мыши.
Немногоsudeo-кода, чтобы продемонстрировать прерывистое вращение камеры.
// This is a potential Unity fix for solving camera translations in general
// for smooth movement
void Update() {
Vector3 msNewPoint = Mouse.Position;
Vector3 adjustedPoint = msOldPoint - msNewPoint;
Vector3 slerpedValue = Vector3.Slerp(msOldPoint, adjustedPoint, 0.2f);
gameObject.Transform.Rotation *= slerpedValue;
}
Я наткнулся на одну и ту же проблему с несколькими экранами, это было для меня простым решением, когда я зажал мышь, чтобы остаться в окне просмотрасама игра.
// Again this is sudo code to demonstrate clamping the mouse to prevent multi
// monitor dpi (IF you are using spanned displays.
// Ie nVidia surround, or AMD Eyefinity.
private Rectangle oldClipRect;
private bool oldClipSet;
void clampMouse(Control control) {
Rectangle screenRect = control.RectangleToScreen(control);
// Initialize this only once to prevent the clip being altered
// when the size of the screen changes
if (!oldClipSet) {
oldClipRect = Cursor.Clip;
oldClipSet = true;
}
// If the control is focused bind the mouse to the game screen,
// otherwise release it.
if (control.Focused)
Cursor.Clip = screenRect;
else Cursor.Clip = oldClipRect;
}