- Home /
Smooth Follow in a 2D Game
Hi, I am making a 2d game where the camera follows a player along the xy axis. So if the character moves up or down the camera scrolls along with it to make sure that the player is always in the middle of the screen. Say the player is moving upwards and the camera is happily scrolling along with it when all of a sudden the player bumps into an obstacle. The camera is supposed to stop scrolling upwards. My problem is I can't get the camera to stop completely once it hits the obstacle. It slowly creeps upwards when i reverse and bump into the obstacle again….How do I get a camera to stop moving when the player hits an obstacle???
Try childing the camera to the player and not having the follow script attached, then it'll tag-along with player because it'll be a part of it. (guess that's what you meant you wanted anyway)
a clearer question -_-
how do you tell if the player has stopped moving because it has hit an obstacle? It still has velocity, it just doesn't go anywhere.
If it's not going anywhere, it has no velocity. By definition. You probably need to improve your physics simulation.
Lo0Nuhti$$anonymous$$: I am doing something a bit more complicated where the camera doesn't follow the player in the negative x, only in the positive. If I child the camera to the player, it will follow in both directions.
syclamoth: When I print out target.velocity.magnitude it says 10...but when i also print out the y position it remains the same so i don't know whats going on there...what i need is a way to tell if an object is moving( i tried the suggestion at http://answers.unity3d.com/questions/34303/deter$$anonymous$$ing-if-a-collider-has-stopped.html but the camera still keeps scrolling a bit after the player has stopped).
yeah, I got that when you posted your other comment earlier.