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

#### Zoltars55

##### Member
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.

#### Yal

##### 🐧 *penguin noises*
GMC Elder
Instance coordinates are the variables x and y, just for the record.

#### woods

##### Member
something as easy as...?

step event of the racket

racket .x = mouse.x

#### 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)