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

#1 2011-07-29 12:41:25

Idome
New Scratcher
Registered: 2011-07-17
Posts: 12

Distance per seconds

Is there a way for a sprite to travel a certain distance every second? Ive been trying to get it to work but everything i try doesn't work. I need a sprite to move to the mouse click.

Offline

 

#2 2011-07-29 12:45:03

DigiTechs
Scratcher
Registered: 2011-04-30
Posts: 500+

Re: Distance per seconds

Easy:
[blocks]
<when green flag clicked>
<forever>
   <if><mouse down?>
   <glide( *lets say 10*  )secs to x sad  <mouse x>  )y sad  <mouse y> ))
   <end>
<end>
[/blocks]

Last edited by DigiTechs (2011-07-29 12:48:16)


I'm back.
Maybe.

Offline

 

#3 2011-07-29 12:46:43

DigiTechs
Scratcher
Registered: 2011-04-30
Posts: 500+

Re: Distance per seconds

Sorry I had to make part of an operator block, its ment to be blue with the Glide block


I'm back.
Maybe.

Offline

 

#4 2011-07-29 12:48:22

Idome
New Scratcher
Registered: 2011-07-17
Posts: 12

Re: Distance per seconds

That doesn't work, because that varies the speed to the distance of the mouse. I want it so the speed says to same no matter the distance.

Offline

 

#5 2011-07-29 12:51:29

DigiTechs
Scratcher
Registered: 2011-04-30
Posts: 500+

Re: Distance per seconds

Oh, there is need of another block here.


I'm back.
Maybe.

Offline

 

#6 2011-07-29 12:55:41

Idome
New Scratcher
Registered: 2011-07-17
Posts: 12

Re: Distance per seconds

I know, completely ruins my idea for a project

Offline

 

#7 2011-07-29 13:00:03

DigiTechs
Scratcher
Registered: 2011-04-30
Posts: 500+

Re: Distance per seconds

Yeah.


I'm back.
Maybe.

Offline

 

#8 2011-07-29 13:20:55

KyleK7
Scratcher
Registered: 2011-06-14
Posts: 500+

Re: Distance per seconds

Ok, I'll try.

[blocks]<when green flag clicked>
           <forever>
           <wait(1 )secs>
           <move( let's say, 10 )steps>
           <end>

Last edited by KyleK7 (2011-07-29 13:22:05)


http://i46.tinypic.com/zwxnhh.gif

Offline

 

#9 2011-07-29 13:41:15

EdnaC
Scratcher
Registered: 2007-08-28
Posts: 100+

Re: Distance per seconds

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

 

#10 2011-07-29 14:50:15

Idome
New Scratcher
Registered: 2011-07-17
Posts: 12

Re: Distance per seconds

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

Offline

 

#11 2011-07-29 15:15:37

Greatdane
Scratcher
Registered: 2007-06-05
Posts: 1000+

Re: Distance per seconds

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

http://i.imgur.com/wVyTD.png

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:

http://i.imgur.com/S70ra.gif


The future belongs to those who believe in the beauty of their dreams.
        ~ Eleanor Roosevelt

Offline

 

#12 2011-07-29 16:04:45

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: Distance per seconds

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>


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#13 2011-07-29 16:17:13

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

Re: Distance per seconds

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.


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

 

#14 2011-07-29 16:23:10

Idome
New Scratcher
Registered: 2011-07-17
Posts: 12

Re: Distance per seconds

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

 

#15 2011-07-29 16:26:25

Idome
New Scratcher
Registered: 2011-07-17
Posts: 12

Re: Distance per seconds

OH, didnt see the greater than block. My mistake.

Offline

 

#16 2011-07-29 18:17:08

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: Distance per seconds

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)


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#17 2011-07-30 06:10:12

Idome
New Scratcher
Registered: 2011-07-17
Posts: 12

Re: Distance per seconds

That works great, but i would like to interrupt it with a new click. Apart from that, it works great. Thanks

Offline

 

#18 2011-07-30 06:21:01

Idome
New Scratcher
Registered: 2011-07-17
Posts: 12

Re: Distance per seconds

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

 

#19 2011-07-30 18:57:17

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: Distance per seconds

<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)


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#20 2011-07-31 05:54:37

Idome
New Scratcher
Registered: 2011-07-17
Posts: 12

Re: Distance per seconds

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

 

#21 2011-07-31 05:59:29

Idome
New Scratcher
Registered: 2011-07-17
Posts: 12

Re: Distance per seconds

This is what ive got:

http://img843.imageshack.us/img843/7936/scriptsw.gif

(scratch wont let me post pictures or links in my post.)

Offline

 

#22 2011-07-31 09:28:00

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: Distance per seconds

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)


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

Board footer