#### Archived

This topic is now archived and is closed to further replies.

# Bouncy Ball

This topic is 5748 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I''ve got a 2d ball, which bounces against the floor. I want it to squish and stretch, cartoon-style. When it hits the floor, it should compress vertically (i.e. flatten) and when it reaches the top of its trajectory, it should be stretched vertically. Basically, the ball is ''springy.'' When it hits the floor, it is exerting a downward force on the floor (which exerts one back), so the spring is compressed - and when in mid-air, it is exerting a force upwards while gravity is downards, so it is stretched. The problem is, I haven''t got any idea about how to approach an implementation for this. I''ve got as far as linking the drawing routine into two variables, squish_x and squish_y, which will scale the sprite in the x and y directions (where squish_x=1/squish_y); and I''ve got spherical collisions happening between the ball and the floor, but I don''t know how to set the squish_x and squish_y variables. I thought that maybe calculating the energy the ball has when it hits the floor (0.5*mass*velocity^2), but I can''t see where to go from that. Any help anyone could provide, in the form of answers or pointers to answers, would be very much appreciated. Thank you. Superpig - saving pigs from untimely fates - sleeps in a ham-mock at www.thebinaryrefinery.cjb.net

##### Share on other sites
*roots thru calc book*

F(y) = -ky
where k is spring stiffness
F is the force restoring to original size, proportional to y, there y is(assumably) compression force.

AKA variant of Hookes law

Hookes
F=kd
where
k is constant
d is distance from orig length

Bugle4d

##### Share on other sites
You should try to keep a constant volume for your ball with squish_x and squish_y. Otherwise, treat your ball as a spring with Hook''s law and all.

Cédric

##### Share on other sites
Ah, ok. So...

1) I calculate the force exerted on the surface (because the ball might not hit it dead-on, of course). The force would be... |velocity| cos (angle between -(surface normal) and ball direction).

So, if V is the velocity vector of the ball, and N is the surface normal, the force is V.N * |N|. And of course N is normalized, so it''s just V.N. Wow, cool.

2) Uh. F is the force I got in step one, and k is my ''magic number'' for the squishiness of the ball. OK, so that gives me the height the ball should squish to?

Am I right so far? If so, how do I make the ball squish over a number of frames? Presumably, the faster it''s moving, the quicker it squishes; and the faster it''s moving, the more it squishes; so would it always take a fixed amount of time to squish?

Thanks so far...

Superpig
- saving pigs from untimely fates
- sleeps in a ham-mock at www.thebinaryrefinery.cjb.net

##### Share on other sites
AFAIK, though a rubber ball deforms when it hits the floor, it doesn''t at the top of a bounce.

##### Share on other sites
TerranFury: That depends on your spring constant. For a very loose spring, it will oscillate on both sides of the resting state, so when the ball is no longer in contact with the floor it will overcompensate and stretch. This isn''t necessarily at the top of the bounce, if that was what you meant.

I''m not a physics major, but I think the ball will also lose some of its kinetic energy in the stretching/squashing, and so won''t bounce as high (think of a deflated basketball). If this is not the effect you want, maybe physical modelling is not the way to go in your case.

##### Share on other sites
No, that is the effect I want. Otherwise the player could just bounce through my level

TerranFury: that may be so, but this is ''cartoony'' physical modelling - the whole ''body moves away very fast but eyes stay for a second'' sort of realm.

##### Share on other sites
TerranFurry is right, and I think that it would look quite odd if the ball was deformed in mid-air. It can continue to "wobble" a little bit after the bounce, but even that is not very cartooney.

Cédric

##### Share on other sites
There is an alternative approach to this problem and I seem to recall posting something along these lines for a thread a few months ago... pity the search function is down.

Treat the ball as either a) a set of surface patches connected by springs; or, b) a set of solid (but not rigid) sub-volumes that transmit forces throughout the ball.

If you''d like further explanation of these methods, just holler.

Cheers,

Timkin

##### Share on other sites
quote:
Original post by Timkin
There is an alternative approach to this problem and I seem to recall posting something along these lines for a thread a few months ago... pity the search function is down.

Treat the ball as either a) a set of surface patches connected by springs; or, b) a set of solid (but not rigid) sub-volumes that transmit forces throughout the ball.

If you''d like further explanation of these methods, just holler.

Thank you (and everyone else), but I think I''ve got something that looks right, at least.

The sub-volumes thing, that''s the idea of splitting the ball up longitudinally, isn''t it? The problem is that when I''m working with a straightforward quad (texture-mapped 2d sprite), that''s not so easy to do; unless, of course, I work with a number of quads, in which case my framerate drops.

TerranFury, cedricl: I''ve got the ball stretching vertically with speed, and it looks ok. At the top of the trajectory, it looks normal, but when moving at a high speed either up or down, it''s stretched.

In case anyone is interested as to how I did it: you don''t really want to know, as most of it came out to be just tweaking numbers. I figured that I only need the ball to actively deform when it has a bottom-edge collision with something (the rest of the time it just passively deforms, based on the vertical velocity as already mentioned). So treating bottom-edge as a special case helped things massively. Other than that, it was just a hodgepodge application of all the things people have been telling me in here (especially the hooke''s law stuff).

Thanks, people.

Superpig
- saving pigs from untimely fates
- sleeps in a ham-mock at www.thebinaryrefinery.cjb.net

1. 1
2. 2
Rutin
23
3. 3
JoeJ
20
4. 4
5. 5

• 22
• 40
• 23
• 13
• 13
• ### Forum Statistics

• Total Topics
631733
• Total Posts
3001927
×