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

#1 2013-02-19 18:29:54

codingdiego
New Scratcher
Registered: 2013-02-11
Posts: 10

Need help with gravity! My sprite keeps falling through the floor!

Hey all!

So i'm working on a side-scroller beat 'em up and I've added gravity to my game to better enhance the gaming experience! The only problem is whenever my sprite jumps, he falls through the floor! Does anyone know what could possibly be the problem with this? I have a ground sprite that is supposed to prevent the sprite from falling through but he falls through anyway!

Any help would be appreciated! Thanks!

Offline

 

#2 2013-02-19 18:58:53

piguillaud
Scratcher
Registered: 2010-06-19
Posts: 100+

Re: Need help with gravity! My sprite keeps falling through the floor!

Do you use velocity?

Offline

 

#3 2013-02-19 19:25:24

bob6
Scratcher
Registered: 2010-07-01
Posts: 100+

Re: Need help with gravity! My sprite keeps falling through the floor!

The problem might be that he is going so fast down that he completely "misses" the ground and seems to fall right through. I have no idea how to fix this problem though, sorry :\


http://i46.tinypic.com/3148ksz.gif

Offline

 

#4 2013-02-19 19:31:53

piguillaud
Scratcher
Registered: 2010-06-19
Posts: 100+

Re: Need help with gravity! My sprite keeps falling through the floor!

If it does use velocity you can limit it. for example, you set it so that if the velocity is faster then x, then the velocity is set to x.
What bob6 said  is true

Offline

 

#5 2013-02-19 19:35:08

codingdiego
New Scratcher
Registered: 2013-02-11
Posts: 10

Re: Need help with gravity! My sprite keeps falling through the floor!

No, I only use Gravity.

Offline

 

#6 2013-02-19 19:38:47

piguillaud
Scratcher
Registered: 2010-06-19
Posts: 100+

Re: Need help with gravity! My sprite keeps falling through the floor!

can you publish your thing? just so that we can take a look and tell you exactly

Offline

 

#7 2013-02-19 20:18:11

codingdiego
New Scratcher
Registered: 2013-02-11
Posts: 10

Re: Need help with gravity! My sprite keeps falling through the floor!

So would velocity fix the problem?

Offline

 

#8 2013-02-19 20:21:22

codingdiego
New Scratcher
Registered: 2013-02-11
Posts: 10

Re: Need help with gravity! My sprite keeps falling through the floor!

Alright, hold on...

Offline

 

#9 2013-02-19 20:27:43

bob6
Scratcher
Registered: 2010-07-01
Posts: 100+

Re: Need help with gravity! My sprite keeps falling through the floor!

Well, velocity is gravity, so I don't understand your problem...


http://i46.tinypic.com/3148ksz.gif

Offline

 

#10 2013-02-19 20:27:56

codingdiego
New Scratcher
Registered: 2013-02-11
Posts: 10

Re: Need help with gravity! My sprite keeps falling through the floor!

How do I share my project? I'm using Scratch BYOB

Offline

 

#11 2013-02-19 20:38:22

codingdiego
New Scratcher
Registered: 2013-02-11
Posts: 10

Re: Need help with gravity! My sprite keeps falling through the floor!

Well, I couldn't upload it so I took a screenshot instead.

http://imgur.com/DPvBgc8

Offline

 

#12 2013-02-19 20:44:52

codingdiego
New Scratcher
Registered: 2013-02-11
Posts: 10

Re: Need help with gravity! My sprite keeps falling through the floor!

I also set Gravity to "-17" when the green flag is clicked. If that helps any.

Offline

 

#13 2013-02-19 20:55:51

powerpoint56
Scratcher
Registered: 2012-04-19
Posts: 500+

Re: Need help with gravity! My sprite keeps falling through the floor!

I think the falling speed is so high, that the sprite misses, and falls right through.

The way to limit the speed could be to add this script:

when gf clicked
forever
set [gravity v] to ((gravity) * (0.93))
Also, when you fall, using a "repeat until" block stops all of the other blocks in that script until the "repeat until" action is done. Maybe you could replace the section with the "if <key [w v] pressed?>" with

if <key [w v] pressed?>
switch to costume [up v]
set [gravity v] to (17)
change y by (15)
end
if <touching color [#F0D1B3]?>
set [gravity v] to (1)
change y by (gravity)
switch to costume [stand v]
else
switch to costume [up v]
change [gravity v] by (-1)
change y by (gravity)
end

Last edited by powerpoint56 (2013-02-19 21:02:02)


http://i48.tinypic.com/2072ctw.gif

Offline

 

#14 2013-02-19 21:21:39

codingdiego
New Scratcher
Registered: 2013-02-11
Posts: 10

Re: Need help with gravity! My sprite keeps falling through the floor!

Alright, so I replaced the code with powerpoint56's recommended code but now he doesn't come back down at all!

Offline

 

#15 2013-02-19 21:27:54

codingdiego
New Scratcher
Registered: 2013-02-11
Posts: 10

Re: Need help with gravity! My sprite keeps falling through the floor!

I uploaded another screenshot of that as well. The sprite never falls back down, he just stays up.

http://imgur.com/vqlOoUA

Offline

 

#16 2013-02-20 09:22:24

powerpoint56
Scratcher
Registered: 2012-04-19
Posts: 500+

Re: Need help with gravity! My sprite keeps falling through the floor!

That's strange. I'd suggest maybe in a forever loop putting

when gf clicked
set [gravity v] to () //whatever you want the gravity to be at at the beginning
forever
set [gravity v] to ((gravity)*(0.92))
change y by (gravity)
That might help the problem; that way you don't have to put in "change y by (gravity)" every single time he jumps and falls.


http://i48.tinypic.com/2072ctw.gif

Offline

 

#17 2013-02-20 14:21:12

Sqervay
New Scratcher
Registered: 2012-10-28
Posts: 52

Re: Need help with gravity! My sprite keeps falling through the floor!

Maybe this project can help you a bit  smile  ...
It's a physics-engine with comments for better understanding the script-parts:
http://scratch.mit.edu/projects/Sqervay/3093325

Offline

 

#18 2013-02-21 22:42:44

codingdiego
New Scratcher
Registered: 2013-02-11
Posts: 10

Re: Need help with gravity! My sprite keeps falling through the floor!

Wow, that Scratch game is PERFECT! Thanks for the link, Sqervay! And a big thanks to everyone else too for helping me out!

Offline

 

Board footer