How do I Keep My Breakout Paddle In The Boundaries?

Get help using Construct 2

Post » Sun Jan 22, 2017 3:58 am

Image

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?
B
18
S
9
Posts: 103
Reputation: 1,817

Post » Sun Jan 22, 2017 4:58 am

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)
Image Image Image
B
32
S
12
G
27
Posts: 761
Reputation: 17,246

Post » Sun Jan 22, 2017 7:20 am

MPPlantOfficial wrote: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! :lol:

Much appreciated.
B
18
S
9
Posts: 103
Reputation: 1,817

Post » Sun Jan 22, 2017 7:51 am

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.
B
62
S
32
G
6
Posts: 126
Reputation: 8,000

Post » Sun Jan 22, 2017 8:13 am

Oh so THAT's how you use clamp. Never knew what it was for.
Image Image Image
B
32
S
12
G
27
Posts: 761
Reputation: 17,246

Post » Sun Jan 22, 2017 5:03 pm

Nice! Both great solutions, thanks folks. :)
B
18
S
9
Posts: 103
Reputation: 1,817

Post » Sun Jan 22, 2017 5:46 pm

You could just set the paddle and walls to solid and they won't pass through each other ;-)
Banned User
B
28
S
7
G
58
Posts: 1,229
Reputation: 34,830


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 23 guests