Weird object throw problem
by Ronald J Nelson · in Torque Game Engine · 05/25/2006 (8:00 pm) · 10 replies
I am not sure if anyone else has seen this before but I have an interesting issue. When I throw an object, any object that can respond to a collision (vehicles, rigidshapes, ect..) that I am looking directly at are sucked towards my character if I contiunue to hold the mouse button after the item has been thrown. My code is standard throw code as you can see.
A little help would be appreciated.
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);
// Since the object is thrown from the center of the
// shape, the object needs to avoid colliding with it's
// thrower.
%obj.setCollisionTimeout(%this);
}A little help would be appreciated.
#2
I don't know where the problems is. This problem is at the bottom of a long list of bugs I have to fix.
05/26/2006 (6:46 am)
I noticed this as well. I use similar code to throw a grenade and on occasion it has been magnetically attracteted to my player. This isn't funny cos once it reaches the player it starts to 'climb' the player, reaches my head and then explodes :)I don't know where the problems is. This problem is at the bottom of a long list of bugs I have to fix.
#3
05/26/2006 (4:13 pm)
Yup thats the one. Well cool it isn't just me then.
#4
05/26/2006 (8:36 pm)
Anyone else seen this? Or any idea what causes it?
#5
05/27/2006 (1:38 am)
Figured it out on my own. The problem lies in the oncollision functions of each of the items also providing a applyimpulse and using the same eye vector business to achieve it. Comment out the items applyimpulse in the oncollision and presto it is now immune to the Jedi Mind trick. A better collsion system would likely be the fix.
#6
06/05/2006 (6:30 am)
However as I found out my mistake in this was not setting up an on(%val) system in my default bind thus providing a "one shot" function system. If you don't have one it continually runs the function rapidly in succession which in this cause causes it to do wierd things.
#7
Has anyone firgured out how to prevent the rising issue?
06/28/2007 (5:46 pm)
OK something weird has happened. this problem has returned but only if you drop the grenade directly below you. Then it rises up and when it explodes it crashes the game. I am assuming the crash is due to the explosion taking place within the player character.Has anyone firgured out how to prevent the rising issue?
#8
Fatal: (c:\torque\sdk\engine\game\fx\explosion.cc @ 915) Error, GL not in canonical state on exit
06/28/2007 (5:53 pm)
Oh and for the explosion problem I got this error when in debug mode.Fatal: (c:\torque\sdk\engine\game\fx\explosion.cc @ 915) Error, GL not in canonical state on exit
#9
05/06/2008 (9:04 pm)
I realize this is an old issue but I never got a real solution for it. Has anyone else?
#10
05/12/2008 (10:30 pm)
OK....Does anyone else have this problem?
Torque Owner Ronald J Nelson
Code Hammer Games