- Home /
camera following player on path
Hi,
is there a good workaround for a camera which is following the player on a predefined path (not behind, but on the side of the player)?
Answer by ScroodgeM · Aug 18, 2012 at 07:24 PM
you can set camera's position as you wish:
always behind player
Camera.main.transform.position = playerTransform.position - playerTransform.forward * 3f;
always to right of player
Camera.main.transform.position = playerTransform.position + playerTransform.right* 3f;
always to right in world space (camera will not rotate on player's rotate)
Camera.main.transform.position = playerTransform.position + Vector3.right* 3f;
always to right and a little at top of player
Camera.main.transform.position = playerTransform.position + playerTransform.right* 3f + playerTransform.up;
also, don't forget to set 'look at' for camera to turn it to player
applying setting position in Update will move camera always following the player
Thank you. In most this will work, but at some points the cam has to rise a little bit higher or woer, This is why I asked for paths. But I will implement you solution for now. Can you tell me what "3f" means in your code?
you can use triggers to mark some areas where camera should move somehow else.
3f is 3 in float format, same as 3.0f. 'f' needed in C# cause else 3.0 will be interpreted as double.
Answer by Dragonlance · Aug 18, 2012 at 09:02 PM
Well you could implement a bezier curve or an array of them.
For this you could also use http://docs.unity3d.com/Documentation/ScriptReference/AnimationCurve.html in your code.
This is a somewhat complex matter, I think this tip is a good starting point for your research.
Your answer
![](https://koobas.hobune.stream/wayback/20220613075846im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
3d platforming Camera 1 Answer
Make the camera follow the players 1 Answer
Camera shake during follow a player with lerp and lookAt? 0 Answers
Camera target 1 Answer
User move camera along path 0 Answers