How do I make it so a object will go there when I click?
Offline
Hi super2sumo,
There are several ways to make a sprite move towards the mouse pointer in Scratch.
One way to make it go to where the mouse was clicked is described here:
http://scratch.mit.edu/forums/viewtopic.php?pid=18947#p18947
Another forum thread about having a sprite follow the mouse pointer is here:
http://scratch.mit.edu/forums/viewtopic.php?pid=12969
This should get you started. If you need to know more, please ask.
Offline
You can do
<when green flag clicked>
<forever if><mouse down?>
<go to x <mouse x> )y
<mouse y>
Offline
Heybrian, that wouldn't work, because you can move th mouse, and then the sprite will just follow the pointer ntil touching it. What we need is to I denticate the place the mouse clicked. This script will work:
<when green flag clicked>
<forever if><mouse down?>
<wait until><< <not> <mouse down?> >>
<set{ x location }to( <mouse x>
<set{ y location }to( <mouse y>
<glide( --- )secs to x <{ x location }> )y
<{ y location }>
Offline
Actally, do this:
<when green flag clicked>
<forever if> <mouse down?>
<wait until> <not> <mouse down?> >>
<glide( --- )secs to x <mouse x> )y
<mouse y>
<end>
Offline
MyRedNeptune wrote:
Heybrian, that wouldn't work, because you can move th mouse, and then the sprite will just follow the pointer ntil touching it. What we need is to I denticate the place the mouse clicked. This script will work:
<when green flag clicked>
<forever if><mouse down?>
<wait until><< <not> <mouse down?> >>
<set{ x location }to( <mouse x>
<set{ y location }to( <mouse y>
<glide( --- )secs to x<{ x location }> )y
<{ y location }>
No, i think i was right because he said go there when CLICKED. it works perfectly to me.
forever if dosnt mean do forever, it means IF.
Edit: Use that same way for gliding, just say
<glide( )secs to x <mouse x> )y
<mouse y>
Last edited by Heybrian (2008-02-20 17:16:54)
Offline
Heybrian and MyRedNeptune have different interpretations of the original request.
MyRedNeptune showed how to go to where the mouse is clicked, even if the mouse is then dragged elsewhere. Hybrian showed how to go to the mouse and follow it as long as the button is held down.
Both actions are useful, and it is not clear which the original poster really had in mind.
Offline
I did it with two sprites.
The first sprite always moves towards the second sprite. The second sprite goes to the mouse, when the mouse is clicked.
Offline