You could point towards the mouse pointer, get the distance to the mouse pointer and use repeat to move. If you find that moves of 1 step give you the speed you want, and the distance to go is 120, just repeat 120 times. If you want to move 2 steps each time, repeat 60. This would give you a constant speed.
Offline
Idome wrote:
That works, but when its close to the mouse pointer it spasms and appears on both sides of the mouse pointer? Any way to stop this
If you see right next to the sprite image, there are buttons, one with a circle arrow, one with a two-directional arrow, and one with a dot. Select one other than the top one and it should stop doing that, or use this script:
Offline
I'm not entirely sure what you want here, but I'll give it a go. This script makes a sprite travel at a constant speed towards the mouse pointer when the mouse is down.
<when green flag clicked>
<forever>
<if><mouse down?>
<point towards( mouse pointer )>
<move( 3 )steps>
<end>
Offline
To add on to what MoreGamesNow suggested, use this to stop it from shaking when it gets close to the mouse pointer:
[blocks]
<when green flag clicked>
<forever>
<if><< <mouse down?> <and> << <not> <( <distance to[ mouse pointer <<> 3 )> >> >>
<point towards( mouse pointer )>
<move( 3 )steps>
<end>[/blocks]
The number in
[blocks]<move( ___ )steps>[/blocks]
and
[blocks] <( distance to mouse pointer <<> ___ )>
[/blocks]
should be the same.
Offline
Thanks for the ideas but what i want is just when you click the mouse, the sprite goes to that spot, traveling the same distance every second. MyRedNeptune, just to point out the distance to 'mouse pointer' wouldnt fit in the Not block.
Offline
So, even if you let go of the mouse it continues to move towards the sprite? Then this:
<when green flag clicked>
<forever>
<if><mouse down?>
<point towards( mouse pointer )>
<repeat( <round( (( <distance to[ mousepointer] > </> 4 )) ) )>
<move( 4 )steps>
<end>
<end>
What this really does is get it within 3 pixels where the mouse was. You can't interrupt it with a new click though. Just ask if you want to be able to interrupt it, and I'll see what I can do.
Last edited by MoreGamesNow (2011-07-29 18:18:19)
Offline
Too work with something else im adding i changed the script so it looks like this:
<when green flag clicked>
<forever>
<if><mouse down?>
<point towards( mouse-pointer
<repeat( <round( ((<distance to[ mouse-pointer </> 2 ))
<if><touching color[ Green
<move( 2 )steps>
<if><touching color[ Blue
<move( 0.5 )steps>
This works but the sprite doesn't always make it to the mouse click. I cant work out how to fix it thoguh
Offline
<when green flag clicked>
<forever>
<if><mouse down?>
<repeat until><< <not> <mouse down?> >>
<point towards( mouse pointer )>
<move( 4 )steps>
<end>
<set{ x }to( <mouse x> )>
<set{ y }to( <mouse y> )>
<repeat until><< <mouse down?> <or> SquareRoot((( (( (( <{ x }> <-> <x position> )) <*> (( <{ x }> <-> <x position> )) )) <+> (( (( <{ x }> <-> <x position> )) <*> (( <{ x }> <-> <x position> )) )) ))) >>
<move( 4 )steps>
<end>
<end>
Okay, this is a little more complicated, but it may seem simpler if I say that I use the distance formula. Here it is in text:
Square Root of( ( (x-xposition) x (x-xposition) ) + ( (y-yposition) x (y-yposition) ) )
* the distance formula is the squareroot of ((x1-x2)^2 + (y1-y2)^2)
Offline
MoreGamesNow wrote:
<repeat until><< <mouse down?> <or> SquareRoot((( (( (( <{ x }> <-> <x position> )) <*> (( <{ x }> <-> <x position> )) )) <+> (( (( <{ x }> <-> <x position> )) <*> (( <{ x }> <-> <x position> )) )) ))) >>
<end>
<end>
I can see hwo the sqrt fits into the or block. The sqrt block is circle while to or blocks is a hexagon block
Offline
sorry about that, the whole squareroot thing in the above post should be in a
<( SquareRootThing <<> 4 )>
block
Last edited by MoreGamesNow (2011-07-31 09:28:25)
Offline