Hello
I have a car game and for various reasons I don't want any dynamic collisions to effect the car. But at the same time I would like some interaction with other objects.
What I want is things like traffic cones, that the player can drive into and knock over... but for this to not effect the car in any way.
I got this working in a hacky way by disabling the contact in PreSolve and then applying fake forces to the traffic cone in BeginContact.
Does anyone know the "correct" way of doing something like this? ideally I would like the traffic cone to react exactly like it would in a normal contact situation.
I'm not using WCK but I am using the Alchemy AS3 port.
Sounds like you want something kind of in-between a kinematic body and dynamic body. You probably could look into how kinematic bodies are handled and hack something into the C++ source code, but that's going to be difficult. The way you are doing things sounds pretty reasonable.
This is a similar issue I'll be facing in an upcoming car game.
I'm wondering what kind of "realistic" effect are you looking for? e.g. If a cone is knocked over, can it be hit again? Should it just be knocked over or slide a little? (Since you mentioned impulse, you are probably looking for some kind of movement)
One possibility is that instead of disabling the cone, make it "light" enough so it doesn't affect the car's movement. This can be done with changing density and perhaps playing around with restitution to create a reasonable bounce effect. Haven't tried it yet though.
The way it works now is it only reacts to begin contact, which actually works really well because if the cone is inside the car nothing happens.
When I say realistically, I mean want the traffic cone to reactive the same way it would if I hadn't disabled the contact.
I remember seeing a top down car game years ago where you could push cones around. Cones weren't even knocked over and you could push all cones around. Seemed fine. Then there were other games where cones were knocked over and sometimes you could push those around, other times cones remained stationary.
If you want to allow "driving over" once the cones have been knocked over, you could change collision mask bits.
After first collision, do you want to cone to collide more?
Yeah I want collisions to happen after the first collision. Its actually working exactly like I want at the minute, I just don't like the result of my begin contact code. There must be a better way to mimic what would happen normally?
I think instead of disabling the contact you might be better off just nullifying the effect of the contact event by applying an equivalent impulse in the opposite direction of the contact event. You can get the manifold & impulses off of the contact event, that's all the data you need to figure out how Box2D compensated for the contact. So just do the opposite on the car (push it slightly toward the cone). You'll have one or two manifold points and both normal & tangential impulses for each point.
This MIGHT work. I had a similar problem where I had to nullify the effect of a contact and it was good enough in the end. You might have some luck posting this question to the general forum as well.
Thank you Mayobutter, I will give it a go.