- Home /
3rd Person Camera collision is jerky when zooming out
I know this question has been asked before several times, but I've spent an entire day trying to figure this out and it still doesn't work.
Basically, I have a 3rd person camera that zooms in on the character when a wall obstructs its view.
void Update()
{
// So that the linecast doesn't hit the player (the player is on a different layer than the world
int layerMask = 1;
RaycastHit hit;
RaycastHit hitBackward;
if(Physics.Linecast(transform.position, transform.root.position, out hit, layerMask))
{
cameraObstructed = true;
transform.position = hit.point;
}
else
{
cameraObstructed = false;
}
if(cameraObstructed == false && (Physics.Raycast(transform.position, -transform.forward, out hitBackward, 0.01f, layerMask)) == false){
// normalPosition is the normal position I want the camera to be when not obstructed
transform.localPosition = normalPosition;
}
}
Now, while the camera is completely functional, whenever it zooms out (so for example when rotating the camera off the floor) the camera's movement is extremely jerky.
Anyone know why this is?
Answer by XGurem · Nov 29, 2019 at 12:33 PM
Change update to FixedUpdate. And add smoothing(Quaternion.Lerp). I think the problem ur facing is that it's competing with the player movement to go first but u want it to adjust after he moves. Try using fixed update first and if that doesn't work add a Lerp variable.
Your answer
Follow this Question
Related Questions
How do I can make this 3rd Person camera Smoother when RayCast? 1 Answer
3rd Person Camera: Keeping it out of objects etc (example)? 0 Answers
3rd Person camera collision 2 Answers
how to view char from side at all times with 3rd person controller 0 Answers
Ray/line casting for camera angle 1 Answer