- Home /
Jerky 3rd Person Camera Following Movement and Rotation
For my 3d game, I have attached a camera to follow my player object in position and rotation change.
But overall I was getting jerky camera follow behavior. I double-checked by stopping the camera follow with player movement behavior. If I don't attach camera to a player then the player has smooth movement and rotation but as I started to follow the player, the screen is started stuttering.
Here is the code that I have used to follow the player object in rotation and position:
public class CameraFollow : MonoBehaviour
{
Vector3 offset;
Quaternion offsetRotation;
//
public Transform target;
[SerializeField] float damping = 1;
void Start()
{
offset = transform.position - target.position;
offsetRotation = transform.rotation;
}
void LateUpdate()
{
if (!target)
return;
float currentAngle = transform.eulerAngles.y;
float desiredAngle = target.eulerAngles.y;
float angle = Mathf.LerpAngle(currentAngle, desiredAngle, Time.deltaTime * damping);
Quaternion rotation = Quaternion.Euler(0f, angle, 0f);
transform.position = target.position + (rotation * offset);
transform.LookAt(target);
transform.rotation *= Quaternion.Euler(-10f, 0f, 0f);
}
}
As per my thinking, transform.LookAt statement creating a problem in smooth motion. Please share your suggestion to make overall feel smooth.
Your answer
Follow this Question
Related Questions
How can i make the camera look up and down through keyboard keys? 2 Answers
Screen is 2 cameras with each different properties. 1 Answer
How can camera smoothly follow a jerky game object? (bouncing up and down) 1 Answer
How can I mimic a Camera from a game to my project? 1 Answer
my screen keeps on jittering when I play what is wrong? here is my camera and movement script 1 Answer