- Home /
How to posistion a camera?
Is there a way to put the camera above an object (the player) and facing down (Top down view) or do I manually move the camera (cant get a good position)
Answer by GesterX · Aug 28, 2010 at 05:12 PM
The following script can be used for a top down camera.
//attach a top down camera var fixedPositionObject : Transform; //y value of camera var heightOfObject = 5;
function Update () { //keep camera following player at specified height fixedPositionObject.position = Vector3(
transform.position.x,
heightOfObject,
transform.position.z
);
}
Simply create a new script with the above code and add it to the character you want the camera to follow. You will need to drag the Main Camera on to the Fixed Position Object variable in the inspector and also set the X rotation of the main camera to 90. Finally adjust the Height Of Object variable as desired.
No Problem. If this answers your question then mark the question as answered so others know your happy.
Answer by jtbentley · Aug 29, 2010 at 02:04 AM
This is pulled out of an iphone app I've worked on.. I've trimmed a lot of the fat (dynamic zoom, etc). The main difference from the one above is that it also dampens the movement of the camera so its less jerky.
// Camera Stuff var mainCam : Transform; // In case you have more than one camera private var mainCamOffset : Vector3; // Temp variable var mainCamXOffset = -3.0; // Offsets var mainCamYOffset = 10.3; // Offsets var mainCamZOffset = -4.5; // Offsets var mainCamDamp = 5; // How much we dampen it by var camTarget : Transform; // What the camera will follow
function Update() { mainCam.position = Vector3.Lerp (mainCam.position, mainCamOffset, Time.deltaTime * mainCamDamp);
mainCamOffset = camTarget.position; // Update the camera's ideal position :)
// Apply the offsets (in case you want to follow in front or behind etc)
mainCamOffset.x += mainCamXOffset;
mainCamOffset.y += mainCamYOffset;
mainCamOffset.z += mainCamZOffset;
}
Your answer
Follow this Question
Related Questions
Deadfrontier type crosshair 1 Answer
Display 1 No cameras rendering when player collides with enemy 1 Answer
How to: Do a camera that is top Down/Isometric 5 Answers
Change Angle of Top Down Camera 0 Answers
Camera Setup for Top Down Shooters 3 Answers