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?