cmuratori
No, technically that is not it. Penetration correction is definitely good, and we'll do that, but _it is the velocity that is the problem_ as I was trying to say. At a contact point you must make the collision routines obey the fact that the relative velocity of the two bodies there must remain 0. Know what I mean?
- Casey
Hmm i still dont get it...
Normally you apply an impulse to both velocities multiplied by both inverse masses. If this impulses then are subtracted from the relative velocity then the relative velocity should be zero right? But only in the direction of the contact normal!
In a simple physics engine we do something like this - without any restitution or multiple shapes:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 | void physicsUpdate() {
for (every entity) {
integrate entity velocity to a new state
}
contacts = [];
for (every entity as A) {
for (every entity as B) {
if (A != B) {
calculate contacts for pair A and B and add it to contacts
}
}
}
baumgarte = 0.2 // We solve the impulses only for 20% to make it more stable
for (iteration from 1 to 10) {
for (any contact) {
relativeVelocity = bodyA.velocity - bodyB.velocity;
impulseScale = relativeVelocity.dot(contact.normal) / (invMassA + invMassB)
impulse = impulseScalar * baumgarte
bodyA.velocity-= impulse * contact.normal * invMassA
bodyB.velocity += impulse * contact.normal * invMassB
}
}
for (every entity) {
integrate entity position from new velocity
}
// lastly we may correct positions using contact.distance so it just touches the surface (This is not needed for simulations, but for games!)
// This part is really hard... and i never have solved this completely :-(
}
|
Normal rigid body stuff but without any angular rotation and no position correction at all. Bodies will sink into each other when mass is too heavy. But it works for simple simulations.
But the way we are doing right now is completely different, we integrate when we move the entity and then handle all the collisions against the other entities. The other entity movements are not taken into account at all.
This may be the core problem of the current state of our collision system, but i really like the way the handmade hero collision system works right now, because its fully stable for static against moving things.
Arrggg collisions are so damn hard... every time i do this, my brain goes crazy.