Bug with collision detection when applying force?

So . . . I found a bug, just not sure if it's with my code or the physics stuff.



I'm creating a PhysicsGameState setting it up and everything, creating a lunar lander (a Box) with four legs (four more Boxes) making them all dynamic physics nodes, attaching them using joints, setting up the translational joint axes, setting minimums, maximums, etc . . . everything works fine.  My lunar lander drops onto a static physics node which contains a big flat expanse of . . . surprise, surprise . . . LAND.



I can hit the space bar and apply thrust, rotate my craft by applying torque . . . everything works fine.



Then I put some damage simulation in.  I set my input handler up to deal with the input from the SyntheticButton objects returned from DynamicPhysicsNode.getCollisionEventHandler().  I start calculating damage . . . voila . . . my lander hits hard . . . legs turn yellow.  Land harder . . . they turn red.  Land SUPER hard, they all disappear due to destruction.



So I start playing with this thing.  My lander hits but survives, so I go to take back off.



Suddenly the legs turn red and disappear.  Hmm . . . odd bug.  Maybe I should rebuild and try again.  Same thing.  What if I take off slower?  Faster?  Take no damage at all?  I tried a few dozen variations.  No matter what, after my lander takes off, I'm getting collision events with the land.  No matter HOW HIGH I GO!!  I DON'T get these collision events BEFORE the lander hits, no matter how close I get.



After much WTFing and hours of slogging through code, I'm at a loss.  Can anybody point me the right direction?  If you need more info I can answer questions or post source code, though there's a fair bit.  I'm using the latest JME and JMEPhysics source out of the CVS repository, so everything should be up to date.



Any ideas?  Anybody?



-Falken

Use the PhysicsDebugger to see where your physics Boxes are and if the have the correct size etc…



PhysicsDebugger.drawPhysics(physicsSpace, renderer);

The newest version shows contact points as well (cyan crosses). You're using ODE impl, I suppose?



How do you compute the contact 'power'? (hard, harder, etc.)

Well, I turned on the debugger.  Nice pretty lines & crosses and everything  :slight_smile:



I'm not really sure what I'm looking for.  I can see contact points very lightly on the surface my lander is hitting.  There's an odd set of flickery lines that point from the world origin to all my lander pieces, but I'm assuming those are just translation vectors of some sort.  That's the only thing I'm seeing that I don't really understand.  I don't see anything out of the ordinary . . . contact points when I'm touching, none when I'm not, but I keep getting input events from that Synthetic Button.  Perhaps that's not the right way of picking up collisions?  The other wierd thing is that I'm only using the 'collisionEventHandler' Syntheic Buttons from the 4 lander legs . . . not the main module, yet occasionally, I'll get events from the main body as well.  Perhaps I'm not using it right?  I SEEM to be following the documentation, but it's not working how I expected.



What I actually suspect is that I'm doing the collision detection wrong by using those event handlers . . . it just seemed like such a slick way to pick up those collisions.  Right now I'm just using the 'ContactInfo' object passed into that collision handler and grabbing the contact velocity vector, grabbing the magnitude and doing some calculations.  When I dump the values, as I start to take off, those contact velocity vectors just keep getting bigger and bigger, but I'm not seeing the effect of it on my ship.



If I'm not wiring things up wrong, I'd guess the actual physics are correct . . . just the event model is mis-wired.  I'll probably dig through the source anyway, just to understand the mechanics of how it all works, but if you guys have any suggestions in the short term, let me know and I'll try it out.



Thanks a mil in the meantime.



-Falken


Maybe you are also getting collision events between the ship and its legs. Are you making sure to only take collisions between the static environment and dynamic ship into account?


There's an odd set of flickery lines that point from the world origin to all my lander pieces

this is because the WorldVectors are not up to date when drawing the physics debug stuff.
You could issue a rootNode.updateGeometricstate(0, true) before drawing the physics to make sure its updated.
But it shouldn't be a problem.

Please try swapping lines 53 and 52 in PhysicsGameState. Does that change anything besides the debug view?

Thanks, irrisor, that fixed the physics debug flickery stuff.



As far as the rest of it, still got problems.  I got a good hour or two now . . . I'll sit down and figure out what's going on.



Thx.



-Falken

Okay so . . . figured it out.  Indeed, it was my stupidity causing the problem, though I must say some of the side effects are a bit odd.



What's wrong with this line?



      inputHandler.addAction(new LegCollisionAction(this), legPhysicsNode.getCollisionEventHandler(), true);



Yeah . . . not so good to allow repeats on collision input.  It's kind of a non-intuitive one, but makes sense in the end.  Very odd, I must say.  Note to self (and anybody else . . . ) allowRepeats = false for collision event handlers.

In any case, thanks y'all for the help with the physics debugging stuff.  Fun to see that working right.

-Falken