Hi all
I have a sprite on the screen, which I want to move towards wherever the cursor is. The code for the sprite I've used is this:
Forever
Repeat<until touching mouse pointer>
Point towards mouse pointer
Move 20
End forever
When I run this, the sprite happily moves towards the cursor. The problem is that when it gets to it, it sort of hovvers around it, moving continually left and right a little bit rather than just stopping. I haven't been able to work out why, or a solution to solve the problem.
Can anyone help please?
Offline
It's in a forever loop, which means it'll keep moving towards the mouse by 20 pixels
However the mouse is only 1 pixel and it might be missing the mouse so it'll keep moving towards it
Offline
If you don't want to change the size of the sprite, here is another solution.
forever
repeat until (distance to [mouse pointer]) < 21
point towards [mouse pointer]
move (20) steps
go to [mouse pointer]
end forever
This will stop the sprite when it is less than 21 steps away from the cursor. Then, wherever it is, it will jump immediately to the mouse pointer.
Offline