How do I Keep My Breakout Paddle In The Boundaries?

0 favourites
  • 7 posts
From the Asset Store
Breakout Bliss design For programming and publishing to other platforms
  • Hi! I'm making a breakout clone (well, it's a breakout clone right now) and I'm having a bit of trouble. The paddle is controlled by the mouse, but unlike being controlled by keys, I can't figure out a way to keep it within the boundaries (the green boxes). Currently it's set to just always follow the mouse's X position, which obviously won't work. As is, it's fine with just going right past the boundaries and off the screen.

    I have also tried making a big sprite/tiled bg and making it so the paddle only follows the mouse when it's over the sprite, i.e. inside the boundaries. But that only kind of worked, because moving too fast from one end to the other causes the mouse to leave the sprite before the paddle catches up to it on the next frame.

    I'm probably just having a brain fart, but I really can't figure it out. Any advice?

  • If Paddle.X <= (Your Lower Bound) | Set Paddle.X to (Your Lower Bound)

    If Paddle.X >= (Your Upper Bound) | Set Paddle.X to (Your Upper Bound)

  • If Paddle.X <= (Your Lower Bound) | Set Paddle.X to (Your Lower Bound)

    If Paddle.X >= (Your Upper Bound) | Set Paddle.X to (Your Upper Bound)

    Thank you! That is a relatively easy solution!

    Much appreciated.

  • You can do it even without conditions, just set Paddle X to "clamp(Mouse.X,100,500)", and play with the numbers accordigly to lower and higher values.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Oh so THAT's how you use clamp. Never knew what it was for.

  • Nice! Both great solutions, thanks folks.

  • You could just set the paddle and walls to solid and they won't pass through each other

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)