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

#1 2013-03-21 17:40:44

troyk
New Scratcher
Registered: 2013-02-06
Posts: 14

WORKING Click-To-Move in Scratch!

So I looked around for a few days for code that allowed me to click the stage and have my sprite move there while changing costumes to make the walking look realistic.
Here is the code that I used  http://tinypic.com/r/10z35w5/6
Also please give credit where credit is due, this is the only code I have seen(maybe I would have found it if I had looked harder) for a workable Click-To-Move in Scratch. Thanks!

P.S. this works with multiple units (which is what I have) I use a Green Selector sprite(which is actually what happens in the game I am recreating) and depending on which sprite the Green Selector sprite is around decides which peon will move.
If anyone would like to see the code for my Green Selector sprite just ask!

Offline

 

#2 2013-03-21 18:12:09

troyk
New Scratcher
Registered: 2013-02-06
Posts: 14

Re: WORKING Click-To-Move in Scratch!

Updates on how the game is going and how I make the peons costume change work with facing the correct way while moving can be posted if anyone shows interest, or maybe I'll just post it here anyway.

Offline

 

#3 2013-03-21 18:30:45

troyk
New Scratcher
Registered: 2013-02-06
Posts: 14

Re: WORKING Click-To-Move in Scratch!

I am currently working on code for a consistent speed.

Offline

 

#4 2013-03-21 19:32:02

troyk
New Scratcher
Registered: 2013-02-06
Posts: 14

Re: WORKING Click-To-Move in Scratch!

Here is the rest of my code for flawless movement (minus costume changes, soon to come). Moves at same speed no matter where you click-to-move



when I receive [Move v]

set [DistanceVariable v] to ( [sqrt v] of ((((mouse x) - ( [x position v] of [Sprite3 v] )) * ((mouse x) - ( [x position v] of [Sprite3 v] ))) + (((mouse y) - ( [y position v] of [Sprite3 v] )) * ((mouse y) - ( [y position v] of [Sprite3 v] )))))


when I receive [Move v]

if <(SinlgePeonSelector) = [1]> 

reset timer

if <( [x position v] of [Sprite3 v] ) > (MouseX)>

repeat until <(timer) > ((DistanceVariable) / (62.5))>  

switch to costume [PeonBirdsEye v]

wait (0.2) secs

switch to costume [costume3 v]

wait (0.2) secs

end

else

repeat until <(timer) > ((DistanceVariable) / (62.5))>  

switch to costume [PeonBirdsEye v]

wait (0.2) secs

switch to costume [costume2 v]

wait (0.2) secs

end

end

switch to costume [PeonBirdsEye v]

end

Offline

 

#5 2013-03-21 20:01:47

troyk
New Scratcher
Registered: 2013-02-06
Posts: 14

Re: WORKING Click-To-Move in Scratch!

Huge thanks to Scratcher LS97 for the plug-in that allowed me to export my blocks of code right onto the forums rather than having to write them out myself/screenshoting it. You can check out the plug-in at http://scratch.mit.edu/forums/viewtopic.php?id=102175

Offline

 

#6 2013-03-21 21:17:07

troyk
New Scratcher
Registered: 2013-02-06
Posts: 14

Re: WORKING Click-To-Move in Scratch!

soooooo my code for the speed at which to move to a spot that is clicked seems to work sometimes and not other times. The code is good i believe, a bug with Scratch I think.

Offline

 

#7 2013-03-22 08:10:43

troyk
New Scratcher
Registered: 2013-02-06
Posts: 14

Re: WORKING Click-To-Move in Scratch!

Actually it now seems to be a flaw in my distance formula, I'm looking into it.

Offline

 

Board footer