Hello,
I am making a platformer where player needs to progress upwards. When the character falls downwards enough, it dies.
My goal is that when the player is moving upwards (positive y-axis) the camera follows him. When player is going downwards the camera would stay at the position already reached and would not follow player until he’s moving upwards again.
The script is now is simply
public Transform player;
void Update () {
transform.position = new Vector3 (0, player.position.y, -10);
}
What is it best way to achieve this?
Thanks!
1st idea in my mind
lets make the function
function UpdateCamera()
{
transform.position = new Vector3 (0, player.position.y, -10);
}
rather then update
now thecamera is waiting from orders.
let the player in his movement script know the camera, and whenever moving up in Y axis, activate
camera.UpdateCamera().
when moving down… simply don’t
2nd idea:
function Update()
{
if(transform.position.y<player.position.y)
{
transform.position = new Vector3 (0, player.position.y, -10);
}
{
hope it helps
Pseudo-code; not copy-pastable
if( (player.position.y > lastPosition) && ((player.position - camera.position) >= tether) )
{
//move camera up
}
Tether is to prevent camera moving up while you are at the bottom of the screen.