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

#1 2010-07-15 17:20:52

Sunrise-Moon
Scratcher
Registered: 2009-06-27
Posts: 1000+

Make a Sprite Go to Mouse but Stay in Grid?

How do I make a sprite go to the mouse, but stay in a grid, like in Coolstuff's Pathing AI?

Last edited by Sunrise-Moon (2010-07-15 17:21:05)


http://i1067.photobucket.com/albums/u427/HulKDzN/RebornBlade.png

Offline

 

#2 2010-07-15 17:24:03

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

Re: Make a Sprite Go to Mouse but Stay in Grid?

Ah, an example of mine! I love it when stuff like this happens.

(For those of you reading this - this script has been fixed! That's said below is no longer relevant  smile  )

Code:

go to x: ((round(((x position of mouse-pointer) / 30) - 0.5) * 30) y ((round(((y position of mouse-pointer) / 30) - 0.5) * 30)

You can change the 30s to however big you want your grid to be. Happy grid-ing!

Last edited by coolstuff (2010-07-24 17:04:15)

Offline

 

#3 2010-07-15 17:57:51

Sunrise-Moon
Scratcher
Registered: 2009-06-27
Posts: 1000+

Re: Make a Sprite Go to Mouse but Stay in Grid?

coolstuff wrote:

Ah, an example of mine! I love it when stuff like this happens.

Code:

go to x: (round(((x position of mouse-pointer) / 30) - 0.5) y (round(((y position of mouse-pointer) / 30) - 0.5)

You can change the 30s to however big you want your grid to be. Happy grid-ing!

Cool, thanks  smile

Edit: It isn't quite working. Mind putting it in block form and taking a pic of teh blockz?

Last edited by Sunrise-Moon (2010-07-15 18:06:49)


http://i1067.photobucket.com/albums/u427/HulKDzN/RebornBlade.png

Offline

 

#4 2010-07-15 18:39:18

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

Re: Make a Sprite Go to Mouse but Stay in Grid?

Sunrise-Moon wrote:

coolstuff wrote:

Ah, an example of mine! I love it when stuff like this happens.

Code:

go to x: (round(((x position of mouse-pointer) / 30) - 0.5) y (round(((y position of mouse-pointer) / 30) - 0.5)

You can change the 30s to however big you want your grid to be. Happy grid-ing!

Cool, thanks  smile

Edit: It isn't quite working. Mind putting it in block form and taking a pic of teh blockz?

Oops! Multiply the entirety of the blocks in the "x" and "y" spots by 30 and it should work like a charm. Unfortunately I cannot blockify it because I am on my iPod.

Offline

 

#5 2010-07-15 18:42:37

Sunrise-Moon
Scratcher
Registered: 2009-06-27
Posts: 1000+

Re: Make a Sprite Go to Mouse but Stay in Grid?

coolstuff wrote:

Sunrise-Moon wrote:

coolstuff wrote:

Ah, an example of mine! I love it when stuff like this happens.

Code:

go to x: (round(((x position of mouse-pointer) / 30) - 0.5) y (round(((y position of mouse-pointer) / 30) - 0.5)

You can change the 30s to however big you want your grid to be. Happy grid-ing!

Cool, thanks  smile

Edit: It isn't quite working. Mind putting it in block form and taking a pic of teh blockz?

Oops! Multiply the entirety of the blocks in the "x" and "y" spots by 30 and it should work like a charm. Unfortunately I cannot blockify it because I am on my iPod.

Works now  smile . Thanks!


http://i1067.photobucket.com/albums/u427/HulKDzN/RebornBlade.png

Offline

 

Board footer