I am making my first mobile game where the player controls a jetpack and the goal is to get as high as possible, I have a camera follow script and my next step is to have it not follow the player if the player is descending. an example of how i want the camera to function is doodle jump where the player dies once he goes below the screen but my game is 2.5D, i’ve tried checking players velocity and if it is negative then don’t follow but nothing is working
You can check the position of the camera vs its position in the last frame, if is lower than the last position then stop your follow script
Float lastPos;
Float camPos;
Bool follow;
Void LateUpdate()
{
camPos = gameobject.transform.position.y; //vertical position of the camera
If(camPos >= lastPos)
{
lastPos = gameobject.transform.position.y;
follow = true;
} else
{
lastPos = gameobject.transform.position.y;
follow = false;
}
}
Then something like this
void Sart()
{
YourFollowScrip camFollow = gameobject.GetComponent<YourFollowScript>();
}
void Update()
{
camFollow.enable = follow;
}