Game Development Community

getting vehicles to work against physics objects YAY!

by deepscratch · in Game Mechanics Kit · 08/25/2009 (12:51 pm) · 8 replies

quick change to get vehicles to work against physics objects:
tested with Bullet physics.
in vehicle.cpp, find
if (collSpeed > mDataBlock->minImpactSpeed)
            onImpact(mCollisionList.mCollision[0].object, collVec);
now add this directly below that:
//.logicking >>	 
// apply impulse
		 if (isServerObject() /*|| Physics::getPhysics(false)!=NULL*/)
		 {
			 for (int i= 0;i<mCollisionList.getCount();i++)
			 {
				 SceneObject* obj = mCollisionList[i].object;
				 if (obj && (obj->getType() & ShapeBaseObjectType))
				 {
					 ShapeBase* shape = static_cast<ShapeBase*>(obj);
					 static float impulseFactor = 0.12f;
					 VectorF force = mMass*impulseFactor*-mCollisionList[i].normal;
					 shape->applyImpulse(mCollisionList[i].point,force);
				 }

			 }
		 }
		 //.logicking <<
recompile, make a wall of boxes, or scatter some boxes about, mount a vehicle and have fun driving into them

#1
08/25/2009 (1:05 pm)
@deepscratch
Awesome stuff! Have to try it by myself!
#2
08/25/2009 (2:02 pm)
Thats odd I thought the collision code included with Rigid::resolveCollision, Vehicle::updatePos, and Vehicle::resolveCollision would do that already as long as you added the necessary script to go with it.

But yeah I tried to drive a vehicle into a softObject without this so far and got a crap load of bad bin range errors. So I will have to try this out and see if it does the trick.

Although it would be even better if you guys made physics vehicles hint hint.
#3
08/25/2009 (11:21 pm)
Awesome! I'll have to try this.
#4
09/02/2009 (1:42 pm)
Just a thought here but in the PhysX resource I released an update to a little while back, vehicles were simply given capsules or such to interact with the world. In this case can't you sort of do the same?
#5
09/04/2009 (8:18 am)
>Just a thought here but in the PhysX resource I released an update to a >little while back, vehicles were simply given capsules or such to >interact with the world. In this case can't you sort of do the same?

Yeah, if the vehicles got the capsule they will be able to collide with clothes and softbodies.
#6
05/22/2010 (3:01 pm)
I can't use vehicles at all since patching in GMK, was hoping this code would help but I guess its something else. Not sure why the default vehicle was affected by adding GMK yet...
#7
05/31/2010 (2:24 pm)
Disabling the physics got me back into vehicles once again. So now I know it's the physics section that is disabling vehicles. I'll putz around with this more when time permits...
#8
06/01/2010 (3:30 pm)
maybe its the binding of the e key set by gmk?... if you had it set to enter the vehicle as in some mods.