Open spacejack opened 9 years ago
The first thing that comes to my mind is, why not use the built in p2 top down vehicle? I guess it's less complex than your own physics but it would make the simulation loop drastically simpler. See https://vine.co/v/em1aAuelJ0l and source at https://github.com/schteppe/p2.js/blob/master/src/objects/TopDownVehicle.js
Feels like your algorithm looks like it should work though... Might be a long shot but, try setting the .contactSkinSize
of your ContactMaterial to zero. If you're using the default one, set world.defaultContactMaterial.contactSkinSize=0;
.
Are you sure that you get a single contact event? Just checking.
What does your custom car physics do? Add friction in the sideways direction? If you replace it with simple extrapolation (x+=v*dt), does it work better?
Do you have some video of this happening, or code?
Ahh now I feel silly! I didn't know p2 had a vehicle. Although I didn't see it in the docs and I worked on the vehicle before I found p2, so that's my excuse. Mine's very simple, I'll try this out and see how it compares.
I get multiple begin/end contact events and they look correct to me. I use a counter, when numContacts > 0 then contact is happening.
Well, the vehicle is new, no wonder you didn't notice it. It's not ben tested much but it should work. Let me know how it goes :)
Hi schteppe,
I'd like to get p2 to handle collision response between a moving rectangle and static shapes (capsules.) The rectangle is moving around using my own custom physics.
I'm having some trouble combining the two and wondered if you had any ideas on how to do this best.
I tried writing my update loop like this:
p2.World.step(dt)
This caused some weird 'sticky' issues during contact. I thought maybe this was because my update was causing the object to penetrate the capsules. So I used my own collision detection to remove the object from overlapping... however this is still causing some weird sticky problems.
I'm wondering if there's a better way to do this. Normally I would simply apply forces to the p2.Body, however since it is a top-down vehicle with its own driving/skid physics, this isn't so easy.