A Flash Developer Resource Site

1. ## 2D Rigid Bodies

Okay, so I've been looking at you people's rigid body movies for the longest time and I always thought it would be really cool to do that stuff on my own.

For the last couple of years I've been dabbling around on and off with rigid bodies, trying to code my own physics simulation. But it just hasn't worked out. I tried reading that Chris Hecker stuff but somehow it didn't all sink in.

I get that each rigid body has a center of gravity/rotation and that the shape of the objects really doesn't matter, just the point of collision.

I know that if you have the two objects' location, linear velocity vector, angular velocity and mass that you can calculate how those velocities will change after a collision at a given point. I just don't understand the equations to do it.

Could someone hook me up with the equations or a simple example of some kind?

I really couldn't care less about collision detection or any of that -- I'm pretty sure I can work that out on my own.

Thanks,
Neal

2. Hard way.

Easy way:
Originally Posted by Fu-Kwun Hwang
[image]
1. Find the time when two ball collide : D= R1+ R2
where D=Distance between center of two balls , and R1/R2 is radius of each balls
2. Find the line connect center of two balls. and calculate the component of the velocitry for each ball alone the line connect those two balls.
For example : Velocity for each ball is Va and Vb (before collision)
Calculate Vap and Vbp. (and another normal component Van,Vbn)
3. It is become a 1D collision problem: ball A with velocity Vap collide with ball B with velocity Vbp . You should be able to calculate velocity after collision for each ball.
for example:
Vap2=((m1-m2)/(m1+m2))vap+ (2m2/(m1+m2))Vbp and
Vbp2=(2 m1/(m1+m2))Vap+((m2-m1)/(m2+m1))Vbp
The tangential component is not changed Van2=Van, and Vbn2=Vbn
4. Calculate the vector sum for velocity of each ball after collision
Va2=Vap2+Van2 and Vb2=Vb2p+Vbn2 (vector summation)
Very easy way.

3. Thanks for the links. The "easy way" totally neglects angular velocity, which is kinda important as I understand it. I'll pour over the 3d one for a while and see if I can figure it out.

4. Originally Posted by Nialsh
The "easy way" totally neglects angular velocity, which is kinda important as I understand it.
my guess is, if your "rigid body" is made of many "balls" that are under constraints (distance from each other), and you solve those with some sort of relaxation, angular velocity will probably be natural side effect.

5. Rigid bodies created from several points and springs are referred to as mass-aggregate.

I believe a mass aggregate engine would be optimal since they are versatile, stable and simple, and things like angular velocity are emergent.

Essentially, you take a few particles, attach them with springs, and run point-line and line-line collision resolution on everything and iterate through it a few times until the result is accurate enough.

6. Just my opinion, but I have found this doesn't work very well. To approximate a rigid body you have to use stiff springs, which reduces the stability limit for the simulation (must be integrated using very small timesteps). If the body is truly rigid, I'd model it using one entity. I would also model its angular momentum explicitly.

Springs can work great and make neat/fun effects - but only when you want lots of springiness (small stiffness values).

7. yeah, i've done stuff with springy bodies before and by the time I got them as stiff as i wanted they started exploding. Plus I'm doing rigid bodies as much for the sake of challenging myself as I am to get the effect. So giving up and doing it another way isn't exactly the point.

8. I took a break from this stuff for a while but now I'm getting back into it. I think I understand most of what's going on with the hard way except one key part:

How do I compute this q thingy?
I'm working in 2D so a cross-product results in a vector with only a z value. That means I can replace the last quantity with a no-magnitude vector, which reduces the whole expression to zero... but can that be right?

And one more thing: I've assumed that my moment of inertia tensor should be a 2x2 matrix in the form: [[n, 0], [0, n]] such that n is an arbitrary number that gives me a nice looking result. Is that valid?

Thanks,
Neal

9. Originally Posted by Nialsh
I'm working in 2D so a cross-product results in a vector with only a z value... which reduces the whole expression to zero... but can that be right?
Yes, but...

Originally Posted by Nialsh
I've assumed that my moment of inertia tensor should be a 2x2 matrix in the form: [[n, 0], [0, n]]
...why don't you do everything in 3D and then just ignore 3rd values?

10. Good thinking. I'm sure it will be a lot of extra computation but there probably won't be a lot of collisions with what I'm doing anyway. It also means I can steal a lot of my code from the example

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

 » Home » Movies » Tutorials » Submissions » Board » Links » Reviews » Feedback » Gallery » Fonts » The Lounge » Sound Loops » Sound FX » About FK » Sitemap