Thursday, May 28, 2015

unity - Make camera follow and rotate with player without childing it


I want to have a camera, that follow the player, without childing it to the player object. So far I have this one line, that follows the player, but does not rotate with it (meaning the camera should look where the player's front is looking, how can I do it?


transform.position = player.transform.position + offset;

Answer



Something like this:


transform.position = player.transform.position - player.transform.forward * distance;
transform.LookAt(player.transform);

where float distance is the distance of camera form player



Consider also the solution 2 : Make camera child of player and in your player die script , you can "deatach" camera from player object


transform.parent = null;

No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...