Question about shape movement
by Claude-Alain Fournier · in Torque Game Engine · 08/16/2004 (1:14 am) · 8 replies
Hi all,
What I am trying to do is to register in DB the item position when thrown by player.
Now my problem is that I always get the player position (object spawn position) here is the code where I spawn the object :
In RegisterObjectPosition I use %obj.getTransform() to get object position but it's still the original position.
Is there a callback or something that could help me there ?
I tried to use onStickyCollision() but it does not work, it's never called.
Thanks in advance for any help.
Regards,
CAF
What I am trying to do is to register in DB the item position when thrown by player.
Now my problem is that I always get the player position (object spawn position) here is the code where I spawn the object :
%obj = new Item()
{
datablock = %datablock;
rotation = "0 0 1 " @ (getRandom() * 360);
//static = true;
//rotate = true;
};
MissionGroup.add(%obj);
%throwForce = %player.throwForce;
if (!%throwForce)
%throwForce = 20;
// Start with the shape's eye vector...
%eye = %player.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,%player.getVelocity());
// Set the object's position and initial velocity
%pos = getBoxCenter(%player.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(%player);
RegisterObjectPosition(%obj) ;In RegisterObjectPosition I use %obj.getTransform() to get object position but it's still the original position.
Is there a callback or something that could help me there ?
I tried to use onStickyCollision() but it does not work, it's never called.
Thanks in advance for any help.
Regards,
CAF
#2
08/16/2004 (1:37 am)
Well Stephen that's not maybe, that's exactly the problem. I though about a schedule() but I keep that solution only if I don't get better solution. But best is to be able to get a callback when the object stop movement (bit like aiPlayer) but I have no idea how to.
#3
schedule a function that checks the object's velocity. If zero, do your registerobj(), if not just have the function schedule itself to check again in the future?
I agree, a script callback would be nicer, you would do something as above in its processTick(). You should set a "check velocity" flag on the object before its applyimpulse to check itself or else all of the game objects would be calling back.
good luck!
-s
08/16/2004 (2:41 am)
How about something like this:schedule a function that checks the object's velocity. If zero, do your registerobj(), if not just have the function schedule itself to check again in the future?
I agree, a script callback would be nicer, you would do something as above in its processTick(). You should set a "check velocity" flag on the object before its applyimpulse to check itself or else all of the game objects would be calling back.
good luck!
-s
#4
08/16/2004 (2:46 am)
There is also an mAtRest variableused in the item code. Looking through item.cc it's already used to determine a collision and when the item stops. You could find a good place where the item hits and is atrest and do your callBack there.
#5
I created a flag mStartMove in item.h I set it to true in applyImpulse() then I check it in updatePos() :
The onStopMove callback is called correctly but still it seems the transform is not yet up to date at this point. Which is strange because the update transform is done just a few line before that code.
08/16/2004 (3:11 am)
I got close to a solution. I created a flag mStartMove in item.h I set it to true in applyImpulse() then I check it in updatePos() :
if (contact)
{
// Check for rest condition
if (!nonStatic && mVelocity.len() < sAtRestVelocity)
{
mVelocity.x = mVelocity.y = mVelocity.z = 0;
mAtRest = true;
mAtRestCounter = 0;
[b]if(mStartMove)
{
Con::executef(mDataBlock, 2, "onStopMove", scriptThis());
mStartMove = false ;
}[/b]
}
// Only update the client if we hit a non-static shape or
// if this is our final rest pos.
if (nonStatic || mAtRest)
setMaskBits(PositionMask);
}The onStopMove callback is called correctly but still it seems the transform is not yet up to date at this point. Which is strange because the update transform is done just a few line before that code.
#6
I had my callback function declared with wrong arguments so I did not get correct transform :
Correct function call is :
So now my code work fine, each time an object is moved around it's end position is saved.
08/16/2004 (6:25 am)
My current implementation work nice. I had my callback function declared with wrong arguments so I did not get correct transform :
Correct function call is :
function ItemData::onStopMove(%this, %obj)
So now my code work fine, each time an object is moved around it's end position is saved.
#8
Your idea work nice. And the implementation is clean.
08/16/2004 (12:29 pm)
Yep Stephen, thanks for the help. Your idea work nice. And the implementation is clean.
Torque Owner Stephen Clark
-s