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

#1 2012-09-17 22:05:47

bullelk12
Scratcher
Registered: 2012-05-26
Posts: 100+

pre sprite detection

I need another difficult script that stops a sprite from falling partially into the ground sprite. You know how that happens when you add gravity to a game but it always stops when it's half buried in the sprite. I want to know a way to stop the sprite exactly on top of the sprite. Is there a good of doing this?


http://mag.racked.eu/cimage/i6000/Achievement++get%21/Scratcher+love+minecraft%21/mca.png

Offline

 

#2 2012-09-17 22:35:05

AtomicBawm3
Scratcher
Registered: 2009-06-27
Posts: 1000+

Re: pre sprite detection

bullelk12 wrote:

I need another difficult script that stops a sprite from falling partially into the ground sprite. You know how that happens when you add gravity to a game but it always stops when it's half buried in the sprite. I want to know a way to stop the sprite exactly on top of the sprite. Is there a good of doing this?

The only really good way of doing this is stopping the sprite and slowly moving it up until there's on a pixel of contact.  This can be done by forcing a loop-like action in a sprite:

if <touching [ground v]?>
  change y by (1)
  set [yvel v] to (0)
if <touching [ground v]?>
  change y by (1)
else
  change y by (-1)
end
if <touching [ground v]?>
  change y by (1)
else
  change y by (-1)
end
if <touching [ground v]?>
  change y by (1)
else
  change y by (-1)
end
if <touching [ground v]?>
  change y by (1)
else
  change y by (-1)
end
if <touching [ground v]?>
  change y by (1)
else
  change y by (-1)
end
end
and so on.  That's the basic idea.


http://i50.tinypic.com/j0yw0p.jpg

Offline

 

#3 2012-09-18 08:00:20

TPAL125
Scratcher
Registered: 2012-06-09
Posts: 18

Re: pre sprite detection

when gf pressed
forever
if <touching [ground v]?>
change y by ((0) - (yvel))
set [yvel v] to ((yvel) / (3))
change y by (yvel)
if <touching [ground v]?>
change y by ((0) - (yvel))
set [yvel v] to ((yvel) / (3))
change y by (yvel)
if <touching [ground v]?>
change y by ((0) - (yvel))
set [yvel v] to ((yvel) / (3))
end
end
end
end
This script is not mine, it's eRKSToCK's, but I use it often and it works.

AtomicBawm3 wrote:

The only really good way of doing this is stopping the sprite and slowly moving it up until there's on a pixel of contact.  This can be done by forcing a loop-like action in a sprite:

There are actually quite a lot of scripts you can possibly use for platforms.

Offline

 

Board footer