This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2008-02-18 22:34:52

super2sumo
Scratcher
Registered: 2008-02-18
Posts: 1

Click and walk

How do I make it so a object will go there when I click?

Offline

 

#2 2008-02-19 04:11:42

Jens
Scratcher
Registered: 2007-06-04
Posts: 1000+

Re: Click and walk

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.


Jens Mönig

Offline

 

#3 2008-02-19 18:33:40

Heybrian
Scratcher
Registered: 2007-12-05
Posts: 100+

Re: Click and walk

You can do


        <when green flag clicked>
        <forever if><mouse down?>
        <go to x sad <mouse x>  )y sad <mouse y>


Black Mesa. go here to get a game 10 times better than SN or FW.  http://scratch.mit.edu/galleries/view/10650
Smiley! copy and paste these into your post or signature!  smile   sad    yikes                 big_smile     wink    tongue    hmm    neutral   cool   lol   mad   roll

Offline

 

#4 2008-02-20 01:51:38

MyRedNeptune
Community Moderator
Registered: 2007-05-07
Posts: 1000+

Re: Click and walk

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 sad  <{ x location }> )y sad  <{ y location }>


http://i52.tinypic.com/5es7t0.png I know what you're thinking! "Neptune! Get rid of those filthy advertisements and give us back the Zarathustra siggy, you horrible person!" Well, don't worry about it, the Zara siggy will be back soon, new and improved! ^^ Meanwhile, just do what the sig tells you to. >.>

Offline

 

#5 2008-02-20 03:58:19

ihaveamac
Scratcher
Registered: 2007-09-22
Posts: 1000+

Re: Click and walk

Actally, do this:

<when green flag clicked>
<forever if> <mouse down?>
<wait until> <not> <mouse down?> >>
<glide( --- )secs to x sad  <mouse x> )y sad  <mouse y>
<end>


~ihaveamac - visit ihaveamac.net

Offline

 

#6 2008-02-20 17:15:26

Heybrian
Scratcher
Registered: 2007-12-05
Posts: 100+

Re: Click and walk

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 sad  <{ x location }> )y sad  <{ 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 sad <mouse x> )y sad <mouse y>

Last edited by Heybrian (2008-02-20 17:16:54)


Black Mesa. go here to get a game 10 times better than SN or FW.  http://scratch.mit.edu/galleries/view/10650
Smiley! copy and paste these into your post or signature!  smile   sad    yikes                 big_smile     wink    tongue    hmm    neutral   cool   lol   mad   roll

Offline

 

#7 2008-02-20 19:33:56

kevin_karplus
Scratcher
Registered: 2007-04-27
Posts: 1000+

Re: Click and walk

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

 

#8 2008-02-21 01:34:44

Mayhem
Scratcher
Registered: 2007-05-26
Posts: 1000+

Re: Click and walk

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.


Web-spinning Spider:  http://scratch.mit.edu/projects/Mayhem/18456
3D Dungeon Adventure:  http://scratch.mit.edu/projects/Mayhem/23570
Starfighter X: http://scratch.mit.edu/projects/Mayhem/21825
Wandering Knight: http://scratch.mit.edu/projects/Mayhem/28484

Offline

 

#9 2008-02-24 14:14:36

dearkids
Scratcher
Registered: 2008-01-15
Posts: 97

Re: Click and walk

Here's my quick way... he wont glide tho.
<when green flag clicked>
<forever>
  <if><mouse down?>
    <go to[ mousepointer ]


Final Fantasy VII's best characters are Cloud, Nanaki, and Cid. Don't deny it.

Offline

 

Board footer