Home > database >  Moving the camera jerkily Unity,C#
Moving the camera jerkily Unity,C#

Time:03-06

I am making a puzzle game with drag-and-drop mechanics. Moving objects is implemented through Configurable Joint. When you click the left mouse button, I put the object attached to the player's body in the Conected body of the dragged object

Joint parameters

Player object hierarchy

RigidBody of the dragged object

Hand's location depends on the player's camera rotation, the rotation script:

[SerializeField] private GameObject _Body;
private float _SensitivityHor = 9.0f, _RotationX = 0, _SensitivityVert = 5.0f, _MinimumVert = -45.0f, _MaximumVert = 45.0f;
void FixedUpdate()
{ 
    //Camera rotation
    Vector3 CameraAngles = transform.localEulerAngles;
    _RotationX -= Input.GetAxis("Mouse Y") * _SensitivityVert;
    _RotationX = Mathf.Clamp(_RotationX, _MinimumVert, _MaximumVert);
    float delta = Input.GetAxis("Mouse X") * _SensitivityHor;
    float rotationY = CameraAngles.y   delta;
    transform.localEulerAngles = new Vector3(_RotationX, rotationY, 0);
    //Body rotation
    Vector3 BodyAngles = _Body.transform.eulerAngles;
    Vector3 _BodyrotationY = new Vector3(BodyAngles.x, CameraAngles.y, BodyAngles.z);
    _Body.transform.eulerAngles = _BodyrotationY;
}

The problem is that when you rotate the camera objects move jerkily (https://www.youtube.com/watch?v=Gn4HS4NIndg), but on the scene all looks fine, I can not figure out what the problem is, please help.

CodePudding user response:

The problem was in the rigidbody of the dragged object, after turning off the interpolation and changing the collision detection to discrete, the camera stopped moving jerkily: Fixed Rigidbody

  • Related