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.
- Use Colliders or Joints if you are using physics.
- Use Mathf.Clamp if you’re using your own movement logic.
- Solve it any other way, there are many ways to solve the problem.
// 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);