- Home /
Question by
Rawmp · Dec 09, 2013 at 10:29 PM ·
javascriptyaxis
How can i set yAxis boundaries for a 2D game?
I'm making a pong-like game and i can't figure out how to set boundaries for the paddle. for example, when i press the key to move the paddle up it moves off the screen.
Comment
Answer by Statement · Dec 09, 2013 at 11:04 PM
Use Mathf.Clamp if you're using your own movement logic.
Solve it any other way, there are many ways to solve the problem.
Example:
// Using Mathf.Clamp to stop yAxis from going below -10 and above 10.
// Apply movement
yAxis += Input.GetAxis("Vertical") * Time.deltaTime;
// Restrict to bounds
yAxis = Mathf.Clamp(yAxis, -10, 10);
Your answer
![](https://koobas.hobune.stream/wayback/20220613123822im_/https://answers.unity.com/themes/thub/images/avi.jpg)