I need help making Pong. I wan the paddle to go to the mouse x without going outside of the lines. There is a box with the paddle in it. It goes to the mouse's x, but still is able to go outside of the box! (The box has a lining on it.) I made it so it goes back to the center if it touches the black lining, but still it doesn't look smooth or efficient. Please help!
Offline
if(mousex>maximumx) { set x to (maximum) } else { if(mousex<minimum) { set x to (minimum) } else { set x to (mouse x) } }
Offline
Well, say the minimum x position is -150, and the maximum is 150, you'd put:
When green flag clicked
Forever
If x position > -150 and 150 > x position
Set x to mouse x
End if
End forever
Or, if you're more advanced, change the bit in the if to "150 > abs of x position"
I hope this helps!
Offline
RedRocker227's script works and is more concise, but it may leave the object past your barriers if the user quickly flicks their mouse left or right past them.
Offline
RedRocker227 wrote:
Well, say the minimum x position is -150, and the maximum is 150, you'd put:
When green flag clicked
Forever
If x position > -150 and 150 > x position
Set x to mouse x
End if
End forever
Or, if you're more advanced, change the bit in the if to "150 > abs of x position"
I hope this helps!
It does, thanks for the suggestion.
Offline