- Home /
How do I make the camera follow my character moving up but not down
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
Answer by marck_ozz · Jan 26, 2021 at 03:49 AM
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;
}
Answer by joshcantcode · Jan 26, 2021 at 12:21 PM
Just a solution off the top of my head, why not use something like
transform.position = new Vector3(x, Mathf.Max(new_y_value, transform.position.y), z);
That way, it can only either be the height you give or the current height.
Your answer
Follow this Question
Related Questions
Terrain into Model 0 Answers
Player Follow Camera Goes Inside Objects 1 Answer
How do I know if a 3d model is Mobile Friendly? 2 Answers
Joystick movement problems 0 Answers