- Home /
How to make the camera to focus on a player
i know how to rotate around player but i want the camera to sort of like track the player were ever he is. and i don't want the camera to rotate as the player does.
Are you after a sentry style camera or a third person style camera. Please provide some more info on the context.
A good place to start is probably the camera.transform.LookAt function.
Answer by graslany · Aug 27, 2013 at 07:11 AM
Hello,
If I get your point right you want that the camera always keep the same looking direction in world space, and simply translates to keep the player in sight. There is a script doing just this in the AngryBots Unity example project. You may want to have a look at and borrow from it.
The main idea is that you have a camera looking direction vector, let's call it vCam and assume it is of length 1. And you have a player located at position pPlayer, located at a distance dCam from the camera. The most rough way of doing tracking is to set the position of the camera to (pPlayer - dCam * vCam) on each Update. Such a basic solution will not do any nice movement smoothing or such things though. That's why you should check out the script in AgryBots, it's more sophisticated.
thanks :) but i got the sctipt from the third person shooter script example after i tried the angrybots game one it wasn't good enough for a third person shooter character.
Your answer
Follow this Question
Related Questions
really annoying rotation problem. 0 Answers
Rotating Produces Odd Results [Unity 2D] 1 Answer
How to use Lerp(Slerp) to rotate on the Z Axis. 3 Answers