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

#1 2012-07-09 11:35:11

11g-tucker
New Scratcher
Registered: 2012-07-09
Posts: 2

how to make the sprite follow the mouse pointer

how do i make the sprite follow the mouse pointer?

Offline

 

#2 2012-07-09 11:39:57

zammer990
Scratcher
Registered: 2012-01-22
Posts: 500+

Re: how to make the sprite follow the mouse pointer

forever
point towards [mouse pointer v]
move (10) steps


http://i45.tinypic.com/2ynq7nn.jpg Play now!

Offline

 

#3 2012-07-09 11:41:25

11g-tucker
New Scratcher
Registered: 2012-07-09
Posts: 2

Re: how to make the sprite follow the mouse pointer

thank you zammer

Offline

 

#4 2012-07-09 13:42:05

Wes64
Scratcher
Registered: 2011-08-19
Posts: 1000+

Re: how to make the sprite follow the mouse pointer

Or this

forever
go to [mouse pointer v]


Experienced 2.0 Tester: Ask me questions!
Using Firefox 13.0, Flash plugin version 11.4.402.287, and Windows XP Professional.

Offline

 

#5 2012-07-09 14:13:53

zammer990
Scratcher
Registered: 2012-01-22
Posts: 500+

Re: how to make the sprite follow the mouse pointer

It depends what you need, if you want it to leg behind the mouse pointer, use mine, if you want it to always go directly to where the mouse pointer is, use wes'


http://i45.tinypic.com/2ynq7nn.jpg Play now!

Offline

 

#6 2012-07-09 14:46:24

r2dav2
Scratcher
Registered: 2011-01-25
Posts: 32

Re: how to make the sprite follow the mouse pointer

Additionally, if you wanted to be fancy, you could do something like this (sorry, not going to make a picture of the blocks XD):

"When Green Flag clicked"
"Forever"
"Point towards mouse-pointer"
"Move 'Distance to mouse-pointer * -1' steps"

.......................................................................................................................

In doing that, it will make the sprite go to the mouse pointer at different speeds; the farther away it is, the faster it will go...
big_smile

Offline

 

#7 2012-07-09 15:18:51

zammer990
Scratcher
Registered: 2012-01-22
Posts: 500+

Re: how to make the sprite follow the mouse pointer

r2dav2 wrote:

Additionally, if you wanted to be fancy, you could do something like this (sorry, not going to make a picture of the blocks XD):

"When Green Flag clicked"
"Forever"
"Point towards mouse-pointer"
"Move 'Distance to mouse-pointer * -1' steps"

.......................................................................................................................

In doing that, it will make the sprite go to the mouse pointer at different speeds; the farther away it is, the faster it will go...
big_smile

Wouldn't work, "distance / 20" would though


http://i45.tinypic.com/2ynq7nn.jpg Play now!

Offline

 

#8 2012-07-09 15:34:01

amcerbu
Scratcher
Registered: 2009-07-21
Posts: 500+

Re: how to make the sprite follow the mouse pointer

You can also do something like this, where the object will move towards the mouse more quickly when it's further away:

when gf clicked
forever
point towards [mouse pointer v]
move ((distance to [mouse pointer v]) / (10)) steps
end

Offline

 

#9 2012-07-09 15:36:51

henley
Scratcher
Registered: 2008-06-21
Posts: 1000+

Re: how to make the sprite follow the mouse pointer

If you want the sprite to follow the mouse, use this, I find 10 to be close, but still smooth. Not taking as long to get to the mouse as 20:

when gf clicked
forever
    point towards [mouse-pointer v]
    move ((distance to [mouse-pointer v]) / (10)) steps
end
But if you want it to follow it so closely, it's almost the mouse itself, you could just use this

when gf clicked
forever
    go to [mouse-pointer v]
end

Last edited by henley (2012-07-09 15:37:50)


"I've worked so hard for you and you give me nothing in return. Do you need help... Or do I?"

Offline

 

#10 2012-07-10 08:55:50

jontmy00
Scratcher
Registered: 2011-11-28
Posts: 1000+

Re: how to make the sprite follow the mouse pointer

There's a wiki article about it here.


FOR ALL THE NEWS ON UPDATES FOR SIMPLISTICRAFT, CLICK HERE.

Offline

 

#11 2012-07-10 09:49:42

SciTecCf
Scratcher
Registered: 2011-11-23
Posts: 1000+

Re: how to make the sprite follow the mouse pointer

Easiest way.

when gf clicked
forever
 point towards [mouse-pointer v]
 move ((distance to [mouse-pointer v]) * (0.1)) steps
end


http://bit.ly/LCZEJRhttp://bit.ly/LSONcOhttp://bit.ly/LF3vIc
http://trinary.site40.net/images/scratchrank.php?username=SciTecCf&display=small

Offline

 

#12 2012-07-10 14:48:27

henley
Scratcher
Registered: 2008-06-21
Posts: 1000+

Re: how to make the sprite follow the mouse pointer

henley wrote:

when gf clicked
forever
 point towards [mouse-pointer v]
 move ((distance to [mouse-pointer v]) / (10)) steps
end

SciTecCf wrote:

when gf clicked
forever
 point towards [mouse-pointer v]
 move ((distance to [mouse-pointer v]) * (0.1)) steps
end

lol


"I've worked so hard for you and you give me nothing in return. Do you need help... Or do I?"

Offline

 

#13 2012-07-11 18:44:30

WillowfurXAmberclaw
Scratcher
Registered: 2012-05-16
Posts: 9

Re: how to make the sprite follow the mouse pointer

:]


If you are totally down, listen to Pinkie's laughter for 20 minutes!!

Offline

 

#14 2012-07-11 18:59:59

henley
Scratcher
Registered: 2008-06-21
Posts: 1000+

Re: how to make the sprite follow the mouse pointer

WillowfurXAmberclaw wrote:

:]

Please only post things that contribute to the topic, or are helpful in some way.


"I've worked so hard for you and you give me nothing in return. Do you need help... Or do I?"

Offline

 

#15 2012-07-15 18:08:18

amcerbu
Scratcher
Registered: 2009-07-21
Posts: 500+

Re: how to make the sprite follow the mouse pointer

@11g-tucker, did one of these solutions do the trick?

Offline

 

#16 2012-07-15 18:10:57

Firedrake969
Scratcher
Registered: 2011-11-24
Posts: 1000+

Re: how to make the sprite follow the mouse pointer

Or [scratchblocks]when gf clicked
forever
if <mouse down?>
point towards [mouse-pointer v]
move (10) steps
else
point towards [mouse-pointer v]
move (5) steps
[scratchblocks]
Can someone fix this for me?

Last edited by Firedrake969 (2012-07-15 18:11:28)


Click the sign.
https://s3.amazonaws.com/eterna/eterna2/logo2.png

Offline

 

#17 2012-07-15 18:30:23

ftf841
Scratcher
Registered: 2012-02-19
Posts: 1000+

Re: how to make the sprite follow the mouse pointer

or:

when gf clicked
forever
glide (1) secs to x: (mouse x) y: (mouse y)

Last edited by ftf841 (2012-07-15 18:31:27)


http://mag.racked.eu/cimage/i9002/Achievement++get%21/Hi+there./mca.png
http://mag.racked.eu/mcimage/i354/Achievement++get%21/CAKE%21%21%21%21%21/mca.png

Offline

 

#18 2012-07-15 18:33:21

ftf841
Scratcher
Registered: 2012-02-19
Posts: 1000+

Re: how to make the sprite follow the mouse pointer

Firedrake969 wrote:

Or

when gf clicked
forever
if <mouse down?>
point towards [mouse-pointer v]
move (10) steps
else
point towards [mouse-pointer v]
move (5) steps
Can someone fix this for me?

fix<ed> scr(i)p<ts>


http://mag.racked.eu/cimage/i9002/Achievement++get%21/Hi+there./mca.png
http://mag.racked.eu/mcimage/i354/Achievement++get%21/CAKE%21%21%21%21%21/mca.png

Offline

 

#19 2013-04-25 17:22:41

mawais888
New Scratcher
Registered: 2013-04-25
Posts: 1

Re: how to make the sprite follow the mouse pointer

when green flag clicked
forever
  point towards [mouse-pointer v]
  if <(distance to [mouse-pointer v]) < [50]>
    move (-10) steps
  end
  if <(distance to [mouse-pointer v]) > [70]>
    move (10) steps
  end
end

Offline

 

#20 2013-04-25 17:32:24

joshuaho
Scratcher
Registered: 2012-08-20
Posts: 100+

Re: how to make the sprite follow the mouse pointer

11g-tucker wrote:

how do i make the sprite follow the mouse pointer?

when gf clicked
forever
if
distance to < [mouse-pointer v] > >[10]// if it is this far away...
point towards [mouse-pointer v]//point towards mousepointer..
move (5) steps//at this speed, move to mousepointer
Or, just do this:
when gf clicked
forever
show
go to [mouse-pointer v] // the sprite will go to pointer without gliding

Last edited by joshuaho (2013-04-25 17:41:59)


Did you know that you can go to space and see Mars by clicking here?

Offline

 

Board footer