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

#1 2012-08-20 15:45:50

moose12141
Scratcher
Registered: 2008-04-03
Posts: 57

Preventing sprite from touching sides

How can I make a script so that the airplane in this game I'm working on doesn't go too far to the side when you move the mouse all the way over? It is programmed to follow the mouse pointer. I don't want players to be able to hide overlapping the side of the screen. Here's the link: http://scratch.mit.edu/projects/moose12141/2723806

Offline

 

#2 2012-08-20 15:53:49

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

Re: Preventing sprite from touching sides

forever
set y to (mouse y)
if <not <([abs v] of (mouse x)) > (boundary)>>
set x to (mouse x)


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

Offline

 

#3 2012-08-20 18:02:11

moose12141
Scratcher
Registered: 2008-04-03
Posts: 57

Re: Preventing sprite from touching sides

So I'll set "boundary" to 220 or something like that, and it should work. Thanks.

Offline

 

#4 2012-08-20 18:09:40

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

Re: Preventing sprite from touching sides

Or you can use something like  (if x position > (240 - radius)) set x to (240 - radius), where radius is an approximate value that determines the "radius" of the plane.  Do the same for the negative, and use 180 for y correction.

Offline

 

#5 2012-08-20 20:52:06

moose12141
Scratcher
Registered: 2008-04-03
Posts: 57

Re: Preventing sprite from touching sides

Thanks for your help. And I'm sure this will be useful for all sorts of projects.

Offline

 

Board footer