Projectiles pushing PhysicsShape (and vector math)
by Aussiemandias · in Torque 3D Professional · 12/07/2013 (12:55 pm) · 1 replies
Hi, I'm trying to get the projectiles to push a physics shape. I'm using bullet physics and have applied the fix from this thread here. http://www.garagegames.com/community/forums/viewthread/135749
This is my code: theoretically I'm just applying the force from the projectile direction onto the shape?
It kind of works, but if I shoot the corner it just spins in a random direction. Can someone help?
This is my code: theoretically I'm just applying the force from the projectile direction onto the shape?
function BulletProjectile::onCollision(%this,%obj,%col,%fade,%pos,%normal)
{
// Apply impact force from the projectile.
if ( %col.getType() & $TypeMasks::ItemObjectType )
{
%vec = %obj.initialVelocity; //projectile doesn't have a getVelocity()
// Add impulse
%col.applyImpulse(%pos, %vec);
}
// Apply damage to the object all shape base objects
if ( %col.getType() & $TypeMasks::GameBaseObjectType )
%col.damage(%obj,%pos,%this.directDamage,"BulletProjectile");
}It kind of works, but if I shoot the corner it just spins in a random direction. Can someone help?
About the author
Associate Ron Kapaun
3tdstudios.com
Looks like a 'Gimbal lock' situation when you shoot the corner of your object. The spin causes the directional to zero out or randomly generate a directional vector. You can probably adjust your object properties (drag and friction) to minimize this effect. However, gimbal lock is always a possibility.
Ron