Discuss Scratch

Hotwire
Scratcher
100+ posts

Stop sprites bouncing when using gravity.

Something I've never figured out is how to add gravity so that sprites don't fall into blocks but also don't bounce.
http://scratch.mit.edu/projects/14757194/

Here's what I mean.
Currently if it's touching the ground the character will move up, if not the character to will move down.
The y velocity is set to 5 if touching the ground to stop the character falling in.

I can do double layers on the ground and reduce it, but I can't do it with just one layer.
lederniersamourai
Scratcher
500+ posts

Stop sprites bouncing when using gravity.

You might add acceleration, i.e. “velocity” of velocity.
When touching the ground acceleration makes velocity decrease.
When moving this will make velocity increase.
Note the if your accelration take only v3 values for instance (0, 1, 5 and same negative values), you can encode that in the formulas that change the velocity.
Hotwire
Scratcher
100+ posts

Stop sprites bouncing when using gravity.

lederniersamourai wrote:

You might add acceleration, i.e. “velocity” of velocity.
When touching the ground acceleration makes velocity decrease.
When moving this will make velocity increase.
Note the if your accelration take only v3 values for instance (0, 1, 5 and same negative values), you can encode that in the formulas that change the velocity.
Did you look at the project I posted?
drmcw
Scratcher
1000+ posts

Stop sprites bouncing when using gravity.

iftouchingbackground?thensetyvto0
Hotwire
Scratcher
100+ posts

Stop sprites bouncing when using gravity.

drmcw wrote:

iftouchingbackground?thensetyvto0
No, that will not allow the sprite to rise when below the background.
If travelling along the line it won't follow it.
drmcw
Scratcher
1000+ posts

Stop sprites bouncing when using gravity.

That's why it's bouncing. Either set it to a small value or change the way you do things and have a repeat until not touching, move -1 function to move out the ground.
Hotwire
Scratcher
100+ posts

Stop sprites bouncing when using gravity.

drmcw wrote:

That's why it's bouncing. Either set it to a small value or change the way you do things and have a repeat until not touching, move -1 function to move out the ground.
*sigh* thanks for not helping…
drmcw
Scratcher
1000+ posts

Stop sprites bouncing when using gravity.

You're more than welcome.
AonymousGuy
Scratcher
1000+ posts

Stop sprites bouncing when using gravity.

I would use a sensor sprite (could even be a clone of the main sprite) which checked to see if it was on the ground.
Hotwire
Scratcher
100+ posts

Stop sprites bouncing when using gravity.

AonymousGuy wrote:

I would use a sensor sprite (could even be a clone of the main sprite) which checked to see if it was on the ground.
Oh, right… explain more?
AonymousGuy
Scratcher
1000+ posts

Stop sprites bouncing when using gravity.

Hotwire wrote:

AonymousGuy wrote:

I would use a sensor sprite (could even be a clone of the main sprite) which checked to see if it was on the ground.
Oh, right… explain more?

I made an example project which shows this method using a sprite which creates a clone of itself. Sorry if the project is hard to understand!
scubajerry
Scratcher
1000+ posts

Stop sprites bouncing when using gravity.

Hotwire
Scratcher
100+ posts

Stop sprites bouncing when using gravity.

Ah, dw I've got something now.
ifttouching background?thenchangeyby1ifttouching background?thenchangeyby1ifttouching background?thenchangeyby1ifttouching background?thenchangeyby1ifttouching background?thenchangeyby1

Last edited by Hotwire (Nov. 29, 2013 19:04:02)

xlk
Scratcher
100+ posts

Stop sprites bouncing when using gravity.

Hotwire wrote:

Ah, dw I've got something now.
ifttouching background?thenchangeyby1ifttouching background?thenchangeyby1ifttouching background?thenchangeyby1ifttouching background?thenchangeyby1ifttouching background?thenchangeyby1
put this in a custom block set to run without screen refresh:
repeat until <not<touching BG>>
change y by
drmcw
Scratcher
1000+ posts

Stop sprites bouncing when using gravity.

Going back to the beginning…what's wrong with setting yv to 1 or is that still too bouncy?
Hotwire
Scratcher
100+ posts

Stop sprites bouncing when using gravity.

drmcw wrote:

Going back to the beginning…what's wrong with setting yv to 1 or is that still too bouncy?
Yes, it also means that the sprite will fall into the blocks before coming back out to make small bounces on the surface.
lederniersamourai
Scratcher
500+ posts

Stop sprites bouncing when using gravity.

So, what you meant is thant when touching ground, you want to move to the exact (perpendicular) distance between ground and the bottom of your sprite.
You can do that by making a block computing that with a binary search with an auxiliary sprite that is shown but made totally ghost.
This is what drmcw proposed except that had to be done on an auxiliary sprite …
Hotwire
Scratcher
100+ posts

Stop sprites bouncing when using gravity.

lederniersamourai wrote:

So, what you meant is thant when touching ground, you want to move to the exact (perpendicular) distance between ground and the bottom of your sprite.
You can do that by making a block computing that with a binary search with an auxiliary sprite that is shown but made totally ghost.
This is what drmcw proposed except that had to be done on an auxiliary sprite …
Problem is resolved no worries.
1timetraveler
Scratcher
11 posts

Stop sprites bouncing when using gravity.

i am working on a project (Test) that envolves just this so ill give you the link when its finished or just look on my page
1timetraveler
Scratcher
11 posts

Stop sprites bouncing when using gravity.

Powered by DjangoBB