How I can make my camera keep a distance between two objects?
Hi, im doing a little game "like" Mario Galaxy and im trying to put my camera on a constant distance between the player and the world.
Im trying with this:
transform.position = (transform.position - player.position).normalized * distance + player.position;
transform.position = (transform.position - gravitySource.position).normalized * (gravitySource.lossyScale.x + distance) + gravitySource.position;
transform.LookAt (player, player.up.normalized);
But if I move the camera to 10 units from player (thats the distance value) and later i move the camera to 30 units from world (distance + world radius) then the camera stops being 10 units from the player.
When the player walks, you can see how the world shakes and I think that shaking is the result of the variable distance between the camera and the player.
I'm doing the player's movements in the Update and the camera's movements in the LateUpdate, Is this correct?
Your answer
Follow this Question
Related Questions
Camera looking at the player at an angle 1 Answer
Dot Product not equals 1 0 Answers
Handheld Camera Shake (Constant Shake)? 1 Answer
Distance between two objects, from the view of the camera. 0 Answers