Game Development Community

Collisions with non-moving player or vehicles

by Ronald J Nelson · in Torque Game Engine · 09/28/2005 (8:51 am) · 9 replies

I have been trying this with the impulses and while I have no problems with moving things, non-moving cars and players don't budge. Is there some way to make them move when you run into them?

Example: Player mounted vehicle collides into a vehicle that is not moving (mounted or not), and the vehicle that was not moving is moved by the collision.

Any help here would be really appreciated.

#1
09/28/2005 (6:43 pm)
I'm interested in this too. Running over people in a vehicle just doesn't work. They stand strong like a titanium reinforced tree.

Maybe making collisions with a vehicle give damage impulses and paired with the ragdoll animation pack maybe we could make the player fly off when hit.
#2
09/28/2005 (6:52 pm)
Nice simile chris. Have you tried making an invisible explosion at the point of impact that could possibly work.
#3
09/28/2005 (7:24 pm)
That is an interesting concept.. but then if anyone just walked up to the vehicle, on collision with the vehicle they'd be injured and flying away :P

We would need it to only cause the explosion and damage if the vehicle was moving a certain speed or higher..

This isn't even getting into account vehicle to vehicle collision and movement. I'm thinking collision like Halo. Deaths on impact, and when a vehicle collides with another vehicle the victim vehicle is tossed a bit. Now we just need to find the best way to do this. ;)
#4
09/29/2005 (3:05 am)
You could use the script callback onCollision to applyImpulse to any objects you hit and scale it by the vehicles velocity. There is an example in the Rigid Shape resource.
#5
09/29/2005 (5:05 am)
Yes actually I have spent several hours working on it, but I have actually a working model now that allows collisions with all types of objects. Just got a lot of tweaking to do.
#6
10/01/2005 (1:16 am)
OK here is what I added to my car.cs file. It still has some problems like the fact that I need to make the amount of impulse more accurate based upon the speed (velocity) of the vehicle I am driving. Also, the car just stops dead in its tracks at lower speeds and passes right through at higher when it comes to collisions with a player character. The code works well in multiplayer but needs tweaking. I am putting it out so others might get to mess with it. All I ask is you post any improvements you might have to it. Thanks everyone.

function WheeledVehicleData::onCollision(%this,%obj,%col,%vec,%speed)
{
   // Collision with other objects, including items
   Parent::onDamage(%this, %obj);

   %obj.damage(0, VectorAdd(%obj.getPosition(),%vec), %vecLen * %this.speedDamageScale, "Impact");// to Run over players
   %col.getClassName();

   if((%this.className $= RigidShapeData || %this.className $= WheeledVehicleData) && %obj.getVelocity() != 0 && %col.getDataBlock().getName() !$= "PlayerBody")
   {
      // Apply an impulse to the object we collided with
      %eye = %obj.getEyeVector();
      %vec = vectorScale(%eye, 1000);
    
      // Add a vertical component to give the item a better arc
      %dot = vectorDot("0 0 1",%eye);
      if (%dot < 0)
         %dot = -%dot;
      %vec = vectorAdd(%vec,vectorScale("0 0 2",1 - %dot));

      // Set the objects position and initial velocity
      %trans = %col.getTransform();

      // Heres the position and rotation.
      %pos = getWords(%trans, 0, 2);
      %col.applyImpulse(%pos,%vec);
   }
   else
   {
      if((%col.getDataBlock().getName() $= "PlayerBody") && %obj.getVelocity() > 10)
      {
         %kickBack = 320;
         %dir = %obj.getEyeVector();
         %position = getWords(%targetObject.getTransform(), 0, 2);
         %x1 = getWord(%dir, 0) * %kickBack;
         %y1 = getWord(%dir, 1) * %kickBack;
         %z1 = getWord(%dir, 2) * %kickBack;
         %impulseVec = %x1 SPC %y1 SPC %z1;
         %col.applyImpulse(%position, %impulseVec);
      }
   }
}

If you hadn't figured out I did add the RigidShape code too and it works perfectly with players and vehicles.
#7
10/01/2005 (8:39 pm)
You might want to expirament with upping the collisionTol of your vehicle (ranges between 0 and 1.0). You can increase the distance at which the collision occures, so that basically your script will run before it makes actual contact with the object, so you could be moving it out of the way before the vehicle touches it (and gets stopped dead by the collision code in the engine). Of course the draw back is that the increase in collision distance will affect all collisions with the vehicle.
#8
10/02/2005 (1:33 am)
Well here is my latest but and it does work against players and cars but with not much more than a nudge on impact.


I set the these values to this now:

collisionTol = 0.6;        // Collision distance tolerance
   contactTol = 0.0;          // Contact velocity tolerance

and made these changes:

function WheeledVehicleData::onCollision(%this,%obj,%col,%vec,%speed)
{
   // Collision with other objects, including items
   //Parent::onDamage(%this, %obj);
   %obj.damage(0, VectorAdd(%obj.getPosition(),%vec), %vecLen * %this.speedDamageScale, "Impact");// to Run over players
   %col.getClassName();

   if((%col.getType() & $TypeMasks::ShapeBaseObjectType || %this.className $= RigidShapeData && %obj.getVelocity !$= 0)
   {
      // Apply an impulse to the object we collided with
      %eye = %obj.getEyeVector();
      %vec = vectorScale(%eye, 1000);
    
      // Add a vertical component to give the item a better arc
      %dot = vectorDot("0 0 1",%eye);
      if (%dot < 0)
         %dot = -%dot;
      %vec = vectorAdd(%vec,vectorScale("0 0 2",1 - %dot));

      // Set the objects position and initial velocity
      %trans = %col.getTransform();

      // Heres the position and rotation.
      %pos = getWords(%trans, 0, 2);
      %col.applyImpulse(%pos,%vec);
   }
}
#9
10/02/2005 (1:38 am)
One annoying thing I am seeing is that the vehicle I am driving into the one that is not moving is getting far more of a collision effect that the one not moving.

Is there some way to adjust the bool atRest to make the players and cars check for collisions anyway under certain conditions like when being collided with by certain objects?