• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

in a brick breaker how to make the racket move with the mouse

Z

Zoltars55

Guest
in a brick breaker how to make the racket move with the mouse and prevent the racket from going out of the screen from left to right?
 

TsukaYuriko

☄️
Forum Staff
Moderator
The mouse's position is stored in mouse_x and mouse_y. You can assign these to the coordinates of any instance.

You can use the clamp function to limit a returned value between a lower and upper bound. The left side of the screen's x coordinate is 0, while the right side's is room_width.
 

TheouAegis

Member
Not that easy. That's just going to make the paddle teleport around the screen.

if abs(mouse_x - x) > 4
hspeed = median(-4, 4, mouse_x - x);

Change the 4 inside the median to how fast the paddle can move.
 

Yal

🐧 *penguin noises*
GMC Elder
something as easy as...?

step event of the racket

racket .x = mouse.x
It would work, but...
and prevent the racket from going out of the screen from left to right?
...it wouldn't stop the racket from going out of the screen.

So we need to limit the racket at the edges of the screen... we could clamp the coordinates at the edges:
GML:
racket.x = clamp(mouse_x, 64, room_width - 64);
(replace the 64 with however much empty space you have outside the level, they don't even need to be the same on the left and right sides)
 
Top