Throwing from on use
by Name · in Torque Game Engine · 01/03/2005 (5:11 pm) · 0 replies
Hey I am trying to write an object such that onUse they throw an object and the one in their inventory dissapears.
So user has object1 in inventory, (item like a medical kit) and when he uses it he want object2 to spawn at his position and be thrown...
this all works like this
function BouncePad::onUse(%this,%user)
{
%user.decInventory(%this, 1);
%obj = new Item()
{
datablock = "ActiveBouncePad";
};
MissionGroup.add(%obj);
%throwForce = 20;
%eye = %user.getEyeVector();
%vec = vectorScale(%eye, %throwForce);
%verticalForce = %throwForce / 2;
%dot = vectorDot("0 0 1",%eye);
if (%dot < 0)
%dot = -%dot;
%vec = vectorAdd(%vec,vectorScale("0 0 " @ %verticalForce,1 - %dot));
%vec = vectorAdd(%vec,%user.getVelocity());
%pos = getBoxCenter(%user.getWorldBox());
%obj.setCollisionTimeout(%user);
%obj.setTransform(%pos);
%obj.applyImpulse(%pos, %vec);
}
--UPDATED 3 TIMES--
once the setCollionTimeout glitch was fixed this all worked perfect... didnt need any help after all... made a nice bounce pad.
So user has object1 in inventory, (item like a medical kit) and when he uses it he want object2 to spawn at his position and be thrown...
this all works like this
function BouncePad::onUse(%this,%user)
{
%user.decInventory(%this, 1);
%obj = new Item()
{
datablock = "ActiveBouncePad";
};
MissionGroup.add(%obj);
%throwForce = 20;
%eye = %user.getEyeVector();
%vec = vectorScale(%eye, %throwForce);
%verticalForce = %throwForce / 2;
%dot = vectorDot("0 0 1",%eye);
if (%dot < 0)
%dot = -%dot;
%vec = vectorAdd(%vec,vectorScale("0 0 " @ %verticalForce,1 - %dot));
%vec = vectorAdd(%vec,%user.getVelocity());
%pos = getBoxCenter(%user.getWorldBox());
%obj.setCollisionTimeout(%user);
%obj.setTransform(%pos);
%obj.applyImpulse(%pos, %vec);
}
--UPDATED 3 TIMES--
once the setCollionTimeout glitch was fixed this all worked perfect... didnt need any help after all... made a nice bounce pad.
About the author