- Home /
I've solved the problem on my own after a few days of troubleshooting.
Third Person Camera Controller Jitter
Hello! I have this problem with my camera. Whenever the camera is looking up and the character walks up a slope, the camera jitters.
I'm pretty sure I narrowed the problem down to the collider.
Heres the code for the Collider:
public float minDistance = 1.0f;
public float maxDistance = 5.0f;
public float smooth;
public float distance;
Vector3 dollyDir;
public GameObject cameraBase;
public FPCamController fpCamController;
// Use this for initialization
void Start() {
distance = transform.localPosition.magnitude;
}
// Update is called once per frame
void Update() {
dollyDir = transform.localPosition.normalized;
Vector3 desiredCameraPos = transform.parent.TransformPoint(dollyDir * maxDistance);
RaycastHit hit;
if (Physics.Linecast(cameraBase.transform.position, desiredCameraPos, out hit)) {
distance = Mathf.Clamp(hit.distance * 0.87f, minDistance, maxDistance);
} else {
distance = maxDistance;
}
transform.localPosition = Vector3.Lerp(transform.localPosition, dollyDir * (distance - .25f), Time.deltaTime * smooth);
print(transform.localPosition);
}
Here's a video of the problem https://youtu.be/UtemMD-_syA P.S. If some of the code is not the best, forgive me I'm new :)
Answer by Glaas · Apr 29, 2020 at 08:57 PM
Hi ! The pinned comment on this video https://www.youtube.com/watch?v=MFQhpwc6cKE should resolve your issue. Indeed, Lerp() is very bad with moving objects. Try using Vector3.SmoothDamp instead.
Hey there! Thanks for trying to help, but it still doesn't seem to work. I noticed it also happens when the character is sprinting. I've noticed that when the camera jitters it moves towards the $$anonymous$$imum distance I set. I have the $$anonymous$$imum distance set to .75, but if I set the $$anonymous$$imum distance to 0 then the camera moves to the opposite Vector3 and stays there. So if it was at (1, 0, -4.5) it would move to (-1, 0, 4.5). Also, it doesn't jitter at all when the character is sprinting backwards or downwards. When I set the $$anonymous$$imum distance to 0 and it flips it will flip back normally if I move backwards. This is definitely really weird.
Follow this Question
Related Questions
FPS Multiplayer setup - TPS models for other clients 1 Answer
Camera smooth transistion 2 Answers
Keyboard / Mouse control for FPS 0 Answers
Movie Textures. 0 Answers
Does anyone know any good 3rd Person Shooter tutorials? 1 Answer