ThrowObject oddity
by gamer · in Torque Game Engine · 06/06/2006 (12:19 pm) · 2 replies
I am using throwObject to have the enemy throw an item toward me, however, it always throws in the opposite way and there are some oddities. I don't have a full understanding of throwObject, why does it always throw in the opposite direction away from me?
thanks
function ShapeBase::throwObject(%this,%obj)
{
// Throw the given object in the direction the shape is looking.
// The force value is hardcoded according to the current default
// object mass and mission gravity (20m/s^2).
%throwForce = %this.throwForce;
if (!%throwForce)
%throwForce = 20;
// Start with the shape's eye vector...
%eye = %this.getEyeVector();
%vec = vectorScale(%eye, %throwForce);
// Add a vertical component to give the object a better arc
%verticalForce = %throwForce / 2;
%dot = vectorDot("0 0 1",%eye);
if (%dot < 0)
%dot = -%dot;
%vec = vectorAdd(%vec,vectorScale("0 0 " @ %verticalForce,1-%dot));
// Add the shape's velocity
%vec = vectorAdd(%vec,%this.getVelocity());
// Set the object's position and initial velocity
%pos = getBoxCenter(%this.getWorldBox());
%obj.setTransform(%pos);
%obj.applyImpulse(%pos,%vec);
error("applyImpuse to "@%pos@", "@%vec);
// Since the object is thrown from the center of the
// shape, the object needs to avoid colliding with it's
// thrower.
%obj.setCollisionTimeout(%this);
}
thanks
function ShapeBase::throwObject(%this,%obj)
{
// Throw the given object in the direction the shape is looking.
// The force value is hardcoded according to the current default
// object mass and mission gravity (20m/s^2).
%throwForce = %this.throwForce;
if (!%throwForce)
%throwForce = 20;
// Start with the shape's eye vector...
%eye = %this.getEyeVector();
%vec = vectorScale(%eye, %throwForce);
// Add a vertical component to give the object a better arc
%verticalForce = %throwForce / 2;
%dot = vectorDot("0 0 1",%eye);
if (%dot < 0)
%dot = -%dot;
%vec = vectorAdd(%vec,vectorScale("0 0 " @ %verticalForce,1-%dot));
// Add the shape's velocity
%vec = vectorAdd(%vec,%this.getVelocity());
// Set the object's position and initial velocity
%pos = getBoxCenter(%this.getWorldBox());
%obj.setTransform(%pos);
%obj.applyImpulse(%pos,%vec);
error("applyImpuse to "@%pos@", "@%vec);
// Since the object is thrown from the center of the
// shape, the object needs to avoid colliding with it's
// thrower.
%obj.setCollisionTimeout(%this);
}
About the author
#2
what's going on?
thanks for any help
06/06/2006 (4:49 pm)
Ok the strange thing is that the problem lies where I call the throwObject(), i call it when the enemy player is hit by my bullet, and since bullet has a radius damage, the damage function player class in called twice. in the 1st time damageType is something like "MyProjectile", the second time the damageType is "Radius". In the 1st case if I call throwObject, the enemy player throws backwards, in the second case he throws forward toward me which is correct. I checked the parameters passing to throwObject is identical in both cases. what's going on?
thanks for any help
Associate Orion Elenzil
Real Life Plus
try commenting out the vertical component and the velocity.
also confirm that %this.throwForce is positive.
put in some echos at various points in the algo to see where exactly %vec is becoming something unexpected.