Box2D Forums

It is currently Wed May 22, 2013 9:37 am

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 10 posts ] 
Author Message
PostPosted: Thu Aug 16, 2012 3:46 pm 
Offline

Joined: Tue Nov 24, 2009 6:15 am
Posts: 38
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.


Top
 Profile  
 
PostPosted: Fri Aug 17, 2012 11:36 am 
Offline

Joined: Fri Dec 14, 2007 8:07 pm
Posts: 913
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.


Top
 Profile  
 
PostPosted: Fri Aug 17, 2012 1:36 pm 
Offline

Joined: Tue Nov 24, 2009 6:15 am
Posts: 38
Howdy Mayobutter

Yeah I figured I was quite close, but I'm not happy with the code I'm using to apply the "fake" forces. Maybe somebody could point me in the right direction, here is what I have in begin contact:

Code:
            var manifold:b2WorldManifold = Registry.Box2dWorld.GetWorldManifold(c, a, b, bias);
            if (manifold.points.length != 0)
            {
               var impulse:V2 = manifold.normal.multiplyN(Math.min(b.m_body.GetLinearVelocity().length() / 7, 3) * b.m_body.GetMass() * bias);
               Body.ApplyImpulse(impulse, manifold.GetPoint());
            }


So, I disable the contact in PreSolve and then use this in BeginContact to make one of the objects react to the collision. Is there a way to better simulate what would happen to the object if I hadn't disabled the contact?


Top
 Profile  
 
PostPosted: Sat Aug 18, 2012 11:54 am 
Offline

Joined: Thu Mar 01, 2012 9:31 am
Posts: 153
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.


Top
 Profile  
 
PostPosted: Sat Aug 18, 2012 12:47 pm 
Offline

Joined: Tue Nov 24, 2009 6:15 am
Posts: 38
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.


Top
 Profile  
 
PostPosted: Sat Aug 18, 2012 3:50 pm 
Offline

Joined: Thu Mar 01, 2012 9:31 am
Posts: 153
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?


Top
 Profile  
 
PostPosted: Sat Aug 18, 2012 4:52 pm 
Offline

Joined: Tue Nov 24, 2009 6:15 am
Posts: 38
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?


Top
 Profile  
 
PostPosted: Tue Aug 21, 2012 2:21 pm 
Offline

Joined: Tue Nov 24, 2009 6:15 am
Posts: 38
Mayobutter, help!


Top
 Profile  
 
PostPosted: Tue Aug 21, 2012 4:18 pm 
Offline

Joined: Fri Dec 14, 2007 8:07 pm
Posts: 913
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.


Top
 Profile  
 
PostPosted: Sun Aug 26, 2012 3:27 am 
Offline

Joined: Tue Nov 24, 2009 6:15 am
Posts: 38
Thank you Mayobutter, I will give it a go.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group