- Home /
Question by
mustang4484 · Jan 30, 2019 at 02:30 PM ·
rotationcamera rotatefollow player
Camera follow car (Y rotation identity)
Hi guys
I would like that my camera follow the car and turn (left and right) togheter within parent. Now i can follow the car but doesn't turn.
Thank you
void Start()
{
offset = transform.position - player.transform.position;
}
void Update()
{
transform.position = offset+player.transform.position;
}
Comment
Answer by xxmariofer · Jan 30, 2019 at 02:40 PM
hello, if you want the camera have a simple functionality of movement and rotation you can just make it child of the car and remove the update, but if you want to do it by code you just need to access
transform.rotation.eulerAngles = new Vector3(transform.rotation.eulerAngles.x, player.transform.eulerAngles.y, transform.rotation.eulerAngles.z);
Answer by Magso · Jan 30, 2019 at 02:42 PM
To match the rotation
transform.eulerAngles = player.transform.eulerAngles;
There was a script called SmoothFollow.js in the import package > scripts menu, though I'm not sure if it's still available in the more recent unity versions.
Checked in Unity 2017.1.1, import package drop menu only has 'custom package...' now.
Just change it to
transform.rotation.eulerAngles = new Vector3(transform.rotation.eulerAngles.x, player.transform.eulerAngles.y, transform.rotation.eulerAngles.z);