im working on a 2d vertical platform-game. and i want my camera to only follow the target up the Y axis. so restrict it from going down the Y axis
How do i do this?
im working on a 2d vertical platform-game. and i want my camera to only follow the target up the Y axis. so restrict it from going down the Y axis
How do i do this?
This is untested so it may contain something wrong but try something like this.
var target : Transform;
var height : float;
var lastheight : float;
function Start ()
}
height = target.transform.position.y;
lastheight = target.transform.position.y;
}
function Update ()
{
height = transform.position.y
if (height > lastheight)
transform.position.y = height;
lastheight = transform.position.y
}
This code goes on the camera. You need to drag in the target object in the editor.
if the heigt of the target exceeds the height of the camera the camera will follow.
This worked perfectly, thanks alot!
var target:Transform;
function Update ()
{
if(target.transform.position.y > Camera.main.transform.position.y)
{
Camera.main.transform.position.y = target.transform.position.y;
}
}