Game Development Community

Getting PhysicsShapes to react to projectiles

by Adam Beer · in Torque 3D Professional · 06/05/2012 (12:53 pm) · 7 replies

Im trying to get some physicsShapes to go flying around when I shoot them but it seems they aren't reacting much/at all to projectiles/explosions. If I shoot the Lurker grenade launcher at a stack of wood pallets they just sit there. Here is my datablock:

datablock PhysicsShapeData(WoodPallet2)
{
category = "PhysicsShapes";
shapeName = "art/shapes/props/wood/woodPalette2/woodPalette2.dts";
mass = "10";
friction = "0.4";
staticFriction = "0.5";
buoyancyDensity = "0.1";
invulnerable = "0";
};

I think I should note that I don't intend to blow them into pieces, just get them to fly around like they should when an explosion goes off right beside them. What am I doing wrong or forgetting?

#1
06/05/2012 (1:12 pm)
Look in the pacific demo under the server/shapebase.cs, and compare it with the one in your project. I think you are missing command that applies the Gamebase damage. Just copy and paste into your project version and see if this fixes the problem. I did this a while ago and can't remember what exactly it was missing. Also making the mass higher has solved other issues too.
#2
06/05/2012 (1:33 pm)
The pacific demo has just the dso files, so I cant read anything. Is there a specific place I should download it to get the source assets?
#3
06/05/2012 (1:41 pm)
Adam, try looking under Products-T3D1.2-Previous Versions-T3D1.1 (2 of 2) for Pacific scripts.
#4
06/05/2012 (2:07 pm)
I noticed that the PhysX Templates don't include any of the physics related scripts or datablock examples for Physics Objects. It's likely that you only have to account for physics objects in the projectile's onCollision() and/or onExplode() callbacks. If memory serves the likely culprit is the ShapeBase typemask in the callback for stock projectiles, and since physic shapes derive from GameBase....
#5
06/05/2012 (2:31 pm)
Add this in shapebase,cs and see if it helps.

function GameBase::damage(%this, %sourceObject, %position, %damage, %damageType)
{
// All damage applied by one object to another should go through this method.
// This function is provided to allow objects some chance of overriding or
// processing damage values and types. As opposed to having weapons call
// ShapeBase::applyDamage directly. Damage is redirected to the datablock,
// this is standard procedure for many built in callbacks.

%datablock = %this.getDataBlock();
if ( isObject( %datablock ) )
%datablock.damage(%this, %sourceObject, %position, %damage, %damageType);
}
#6
06/05/2012 (10:08 pm)
Thank you gentlemen. It seems PhysicsShape doesn't work the way I thought it did. It seems that it wants to just delete the shape once I shoot it and replace it with the debris shape.

So I tried creating a debris shape with the same shape file, shot it and the thing tipped over..yay! Then I shot it again and there was no collision on the debris.

All I want to be able to do is shoot around a shape that doesn't break or disappear, what am I doing wrong?

datablock PhysicsDebrisData( WarningBarrierDebris )
{
   lifetime = 9999999;
   lifetimeVariance = 0.0;

   velocity = 0.1;
   velocityVariance = 0;
   
   shapeFile = "art/shapes/props/walls/warningBarrier001/warningBarrier001.dts";
   
   mass = 10;
   dynamicFriction = 0;
   staticFriction = 0.5;
   restitution = 0.0;
   linearDamping = 0.0;
   angularDamping = 0.0;
   linearSleepThreshold = 1.0;
   angularSleepThreshold = 1.0;
   waterDampingScale = 1.0;
   buoyancyDensity = "0.1";
   castShadows = "1";
   friction = "0.4";
};
datablock PhysicsShapeData(WarningBarrier)
{
   category = "PhysicsShapes";
   shapeName = "art/shapes/props/walls/warningBarrier001/warningBarrier001.dts";
   mass = "10";
   friction = "0.4";
   staticFriction = "0.5";
   buoyancyDensity = "0.1";
   invulnerable = "0";
   //debris = WarningBarrierDebris;
};
#7
06/06/2012 (12:59 am)
If you want a physics shape to move around with impulses and gravity it needs to have a non 0 mass like you have in your WarningBarrier.

After that all you need to do is run the applyImpulse function on the object, the code from the pacific demo doesn't do this, it just runs the destroy function which swaps the physicsShape for the physicsShapeDebris object.

Look at some of the other examples using the applyImpulse function like raduisdamage.cs if you haven't used it before.