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

#1 2011-12-31 14:45:01

DanCstudio
Scratcher
Registered: 2011-10-05
Posts: 12

Walk to mouse?

I'm creating an RPG like RuneScape, where you have to click where you want to go to.
The thing is, I can't devise a script for this, as I'm fairly new to this.
Help?
smile

Offline

 

#2 2011-12-31 15:10:35

StoryMaker
Scratcher
Registered: 2007-05-06
Posts: 27

Re: Walk to mouse?

I'm not an expert, but this worked in my project:

[blocks]
<when green flag clicked>
<forever>
<wait until><mouse down?>
<glide( 1 )secs to x sad  <mouse x> )y sad  <mouse y>
<end>
[/blocks]

Last edited by StoryMaker (2011-12-31 15:11:32)


~The Signature of the Me~
My Neopets account is storymakerechidna...my Club Penguin account is Caecilian...I like Sonic the Hedgehog...and I am cool!

Offline

 

#3 2011-12-31 15:30:58

DanCstudio
Scratcher
Registered: 2011-10-05
Posts: 12

Re: Walk to mouse?

Thanks alot!

Offline

 

#4 2012-01-01 15:33:57

RedRocker227
Scratcher
Registered: 2011-10-26
Posts: 1000+

Re: Walk to mouse?

I made a project, with a perfect method!
Download it to see the scripts ^_^
http://scratch.mit.edu/projects/RedRocker227/2250984

Last edited by RedRocker227 (2012-01-01 17:00:54)


Why

Offline

 

#5 2012-01-02 08:57:29

RedRocker227
Scratcher
Registered: 2011-10-26
Posts: 1000+

Re: Walk to mouse?

And I think this would belong better in the All About Scratch forum.
I'll report it to be moved, okay? c:


Why

Offline

 

#6 2012-01-02 09:54:55

coolstuff
Community Moderator
Registered: 2008-03-06
Posts: 1000+

Re: Walk to mouse?

RedRocker227 wrote:

And I think this would belong better in the All About Scratch forum.
I'll report it to be moved, okay? c:

Good plan.  smile

Offline

 

#7 2012-01-02 12:54:20

LewisZapata-Lee
New Scratcher
Registered: 2011-11-30
Posts: 45

Re: Walk to mouse?

StoryMaker wrote:

I'm not an expert, but this worked in my project:

[blocks]
<when green flag clicked>
<forever>
<wait until><mouse down?>
<glide( 1 )secs to x sad  <mouse x> )y sad  <mouse y>
<end>
[/blocks]

The thing about this is, if you move the mouse, the character will start to head towards the new position.  if you don't want this, you will need two variables (walk x and walk y). 

when green flag clicked
|if <mouse down?>|
|wait until <not<mouse down?>>|
|set walk x to (mouse x)|
|set walk y to (mouse y)|
glide [{speed}] to x: (walk x) y: (walk y)|

hope this helps!

Offline

 

#8 2012-01-02 13:24:01

SJRCS_011
Scratcher
Registered: 2011-02-07
Posts: 1000+

Re: Walk to mouse?

LewisZapata-Lee wrote:

StoryMaker wrote:

I'm not an expert, but this worked in my project:

[blocks]
<when green flag clicked>
<forever>
<wait until><mouse down?>
<glide( 1 )secs to x sad  <mouse x> )y sad  <mouse y>
<end>
[/blocks]

The thing about this is, if you move the mouse, the character will start to head towards the new position.  if you don't want this, you will need two variables (walk x and walk y). 

when green flag clicked
|if <mouse down?>|
|wait until <not<mouse down?>>|
|set walk x to (mouse x)|
|set walk y to (mouse y)|
glide [{speed}] to x: (walk x) y: (walk y)|

hope this helps!

[/blocks]The first was what the user wanted.  This can probably be closed, though.
And don't forget [/blocks]!

Last edited by SJRCS_011 (2012-01-02 13:24:32)


http://i.imgur.com/vQqtH.png
Learning to Program in a Nutshell:  "You're missing a closing parentheses" - LS97

Offline

 

#9 2012-01-02 13:55:37

RedRocker227
Scratcher
Registered: 2011-10-26
Posts: 1000+

Re: Walk to mouse?

LewisZapata-Lee wrote:

StoryMaker wrote:

I'm not an expert, but this worked in my project:

[blocks]
<when green flag clicked>
<forever>
<wait until><mouse down?>
<glide( 1 )secs to x sad  <mouse x> )y sad  <mouse y>
<end>[/blocks]
[/blocks]

The thing about this is, if you move the mouse, the character will start to head towards the new position.  if you don't want this, you will need two variables (walk x and walk y). 

when green flag clicked
|if <mouse down?>|
|wait until <not<mouse down?>>|
|set walk x to (mouse x)|
|set walk y to (mouse y)|
glide [{speed}] to x: (walk x) y: (walk y)|

hope this helps!

No, it won't start walking towards the new position.
Once it starts gliding, it continues to glide towards the coordinates of the mouse when it was clicked, it doesn't change.
I wouldn't recommend using the glide block anyway though; it would sometimes go faster than other times, depending on the distance to the mouse-pointer when it's clicked.
If you want to see a method that makes the speed constant, I've made a project for it. Link in my earlier post ^_^

Last edited by RedRocker227 (2012-01-02 13:55:59)


Why

Offline

 

#10 2012-01-05 12:25:02

K-Jam
Scratcher
Registered: 2010-04-17
Posts: 100+

Re: Walk to mouse?

StoryMaker wrote:

I'm not an expert, but this worked in my project:

[blocks]
<when green flag clicked>
<forever>
<wait until><mouse down?>
<glide( 1 )secs to x sad  <mouse x> )y sad  <mouse y>
<end>
[/blocks]

yeah, probably something like that or:
<when green flag clicked>
<forever>
<if><mouse down?>
<glide(  )secs to x sad   <mouse x>)y sad  <mouse y>


http://images.inmagine.com/img/imagezoo/iz162/Iz162012.jpg COMPASS!!!

Offline

 

#11 2012-01-05 16:05:48

GameCentral
Scratcher
Registered: 2011-10-05
Posts: 100+

Re: Walk to mouse?

Sorry to post here, but could you take my test.


http://i1237.photobucket.com/albums/ff468/sciteccf/gamecentral.gif
http://i.imgur.com/2RYxb.png

Offline

 

#12 2012-01-07 15:07:06

zippynk
Scratcher
Registered: 2011-07-23
Posts: 500+

Re: Walk to mouse?

I think there's a "go to" block. You could use it and select mouse-pointer. It would look something like this.

Last edited by zippynk (2012-01-07 15:34:16)


https://dl.dropbox.com/u/60598636/trifocal_interlude_soundcloud_button.png

Offline

 

Board footer