- Home /
smooth camera rotation problem
So... I've been trying to make a simple 3rd person script where the camera follows the player. I figured that the camera rotation of the player should be smooth. This is where I've been having trouble. I've tried to refit script from the camera following the translation of the player but it doesn't seem to work. Hopefully this is an easy fix. Sorry about this, I've just started to learn with unity's scripting tutorials... It hasn't done me much good in this situation.
If you simply pasted your code in your post it would simplify it for others to edit it and add possible answers.
Answer by xxmariofer · Feb 19, 2019 at 09:06 AM
dont access the transform of a transform. dont do Target.transform change it to Target.rotation/position. second you need to lerp the roation not the position so you need to access the Target.rotation and calculate the desired rotation. also in the last line you are probably missing a '+'. not sure if you are missing something else.
unfortunately, there is now a problem on 'DesiredPosition'. The error states that it's not able to convert a Vector3 to a Quaternion
public Transform Target;
public Vector3 offset;
float Smooth = 0.25f;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
Vector3 desiredPosition = Target.transform.position + offset;
transform.rotation = transform.rotation.Lerp(***desiredPosition***, Target.rotation, Smooth);
transform.LookAt(Target);
transform.position = Target.position + offset;
you are mixing position and rotation, and the code makes no sense, you want the object to lerp the position or the rotation? but if you only want to get that code going you can change that line to this
transform.rotation = transform.rotation.Lerp(Quaternion.Euler(desiredPosition), Target.rotation, Smooth);
I apologize, but the script haws another flaw. This is one I can't figure out, like the last 2. The problem is now the transform.rotation.Lerp has an error. It states that it can't be accessed with an instance reference. It proceeds to suggest to qualify with a type name ins$$anonymous$$d. Here's the code:
public Transform Target;
public Vector3 offset;
float Smooth = 0.25f;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
Vector3 desiredPosition = Target.transform.position + offset;
transform.rotation = transform.rotation.Lerp(Quaternion.Euler(desiredPosition), Target.rotation, Smooth);
transform.LookAt(Target);
transform.position = Target.position + offset;
}
}
unimportant: I apologize if I'm a nuisance to anyone, this 'code' has an extent before in my $$anonymous$$d it becomes gibberish