- Home /
Question by
wwidelec1 · Oct 19, 2018 at 12:30 AM ·
cameralookatfollow player
Camera shake during follow a player with lerp and lookAt?
Hi! Heres my code for cam rotating with player around Vector3.zero. Camera is shaking rapidly several times in a second. It use lerp, so i thing there is a problem with transform.position maybe? I tried to assign pos in Update, and lerp in LateUpdate but it didnt help. Any solutions, please?
public class CameraFollow : MonoBehaviour {
private Vector3 camOffset=new Vector3(0f,-8.5f,10.5f);
public Transform target;
private Vector3 dirVector;
private float distance;
void Start () {
transform.position = target.transform.position - camOffset;
distance = Vector3.Distance (target.transform.position, transform.position);
distance+= Vector3.Distance (new Vector3 (0f, target.position.y, 0f) , target.position);
}
void Update()
{
}
// Update is called once per frame
void FixedUpdate() {
Follow ();
}
void Follow()
{
dirVector= ( target.position-new Vector3 (0f, target.position.y, 0f)).normalized;
dirVector *= distance;
dirVector.y += target.position.y+6.5f;
Vector3 smoothedPos = Vector3.Lerp (transform.position, dirVector, PlayerController.instance.cameraSmooth);
transform.position = smoothedPos;
transform.LookAt (target);
}
}
Comment
Your answer
Follow this Question
Related Questions
Demons Souls Fall death Camera 1 Answer
LookAt doesn't work properly with OVRCameraRig 2 Answers
transform.lookat() limitation... 1 Answer
How Can I Stop Rotation From This Script? 0 Answers
Look at wont update? 2 Answers