- Home /
Follow after height
Hi i've got a question. How can I do a camera like here:
http://www.youtube.com/watch?feature=endscreen&NR=1&v=Z2O3XpQZSng
A camera that only follows the player when he reached a special height?
Answer by Seth-Bergman · Apr 30, 2012 at 07:38 PM
var playerHeight : float;
var player : Transform;
var raiseCameraMinHeight : float;
var raiseSpeed : float = 5.0;
var baseHeight : float;
function Start()
{
if(!player)
player = GameObject.FindWithTag("player");
}
function Update ()
{
playerHeight = player.position.y;
if(playerHeight > raiseCameraMinHeight)
{
var targetHeight = (playerHeight - raiseCameraMinHeight);
transform.position.y = Mathf.Lerp(transform.position.y, baseHeight + targetHeight, Time.deltaTime * raiseSpeed);
}
else
transform.position.y = Mathf.Lerp(transform.position.y, baseHeight, Time.deltaTime * raiseSpeed);
}
//think this should do it, be sure to set the cameraRaiseMinHeight var to the desired height to start raising, and the baseHeight to the lowest height the camera should go .. and tag your player as "player".. Oh yeah, this script would go on the camera, hope this helps
thank you veeeery much. Why are the people in this forum so clever thank you ;D
But I firstly have to try it
Your answer
Follow this Question
Related Questions
Super Meat Boy Styled Camera? 1 Answer
Camera not rotate when following player 1 Answer
How to get camera to follow player 2d 11 Answers
How do i get a camera to follow a Bird/Plane smoothly? 2 Answers
How to do a plane follower? 3 Answers