CollidedObject always 0 ?
by Very Interactive Person · in Torque Game Engine · 05/24/2004 (12:41 am) · 9 replies
Why is collidedObject always 0 in this code?:
Is this no longer in the engine? was it ever there? I would like to be able to detect what it is I am crashing into. Is this possible?
function WheeledVehicleData::onImpact(%data, %vehicleObject, %collidedObject, %vec, %vecLen)
{
echo("vehicleObject: " @ %vehicleObject @ " collideObject: " @ %collidedObject);
}Is this no longer in the engine? was it ever there? I would like to be able to detect what it is I am crashing into. Is this possible?
#2
05/24/2004 (1:38 am)
OnCollision is not what I want... I want to use onImpact becuase this is called once, upon impact.
#3
05/24/2004 (8:20 am)
Can someone with some C++ experience please tell me what I would need to change to have the collided object passed? I mean the collision is detected, so it shouldn't be hard to pass the collided object? Or am I wrong?
#4
05/24/2004 (10:09 am)
Check the code that detects impact, try searching for Con::executef(this, "onImpact"... or just onImpact, it's probably passing a 0 instead of the object, never checked.
#5
But, anyway... here's what I think it does:
in vehicle.cc there's:
now in shapebase.cc there's:
So, its using the second function... and that one is indeed passing "0"... and I don't really see a way of passing it the collided object. Can I pass it? it isn't even passed to the function. Where should I look?
05/24/2004 (3:44 pm)
Owk... sorry if the following sounds dumb... I only took a couple of classes of C++ like 2 years ago ;) Most of the things I do with Torque are completely script based...But, anyway... here's what I think it does:
in vehicle.cc there's:
if (collided) {
VectorF collVec = mRigid.linVelocity - origVelocity;
F32 collSpeed = collVec.len();
if (collSpeed > mDataBlock->minImpactSpeed)
onImpact(collVec);
}now in shapebase.cc there's:
void ShapeBase::onImpact(SceneObject* obj, VectorF vec)
{
if (!isGhost()) {
char buff1[256];
char buff2[32];
dSprintf(buff1,sizeof(buff1),"%f %f %f",vec.x, vec.y, vec.z);
dSprintf(buff2,sizeof(buff2),"%f",vec.len());
Con::executef(mDataBlock,5,"onImpact",scriptThis(), obj->getIdString(), buff1, buff2);
}
}
void ShapeBase::onImpact(VectorF vec)
{
if (!isGhost()) {
char buff1[256];
char buff2[32];
dSprintf(buff1,sizeof(buff1),"%f %f %f",vec.x, vec.y, vec.z);
dSprintf(buff2,sizeof(buff2),"%f",vec.len());
Con::executef(mDataBlock,5,"onImpact",scriptThis(), "0", buff1, buff2);
}
}So, its using the second function... and that one is indeed passing "0"... and I don't really see a way of passing it the collided object. Can I pass it? it isn't even passed to the function. Where should I look?
#6
05/24/2004 (6:50 pm)
Make the first section of the code use the first onImpact instead of the second, maybe?
#7
05/24/2004 (7:19 pm)
Sado speaks the truth here, since the vehicle code is calling onImpact with a single parameter it's calling the later overload. Pass the object along in onImpact and you should be fine.
#8
I'm not that stupid ;) The question was more what should I pass? I really don't see what var to pass... I mean in vehicle.cc. I don't see how I can pass it.
05/25/2004 (8:30 am)
Quote:Make the first section of the code use the first onImpact instead of the second, maybe?
I'm not that stupid ;) The question was more what should I pass? I really don't see what var to pass... I mean in vehicle.cc. I don't see how I can pass it.
#9
Then pass that to the onImpact.
Sorry for not giving you more specific instructions. :)
05/25/2004 (9:28 am)
Ah, I see what's going on. Looks like you're going to have to modify some of the collision detection code to store the last object it collided with so you can pass it to script. I'd set up a SimObjectPtr mLastCollided and then each time I resolve a collision write the object into it that I collided with.Then pass that to the onImpact.
Sorry for not giving you more specific instructions. :)
Torque Owner Mark Miley