Game Development Community

Direction of a Standstill Vehicle

by arda · in Torque Game Engine · 09/23/2005 (1:10 am) · 5 replies

Hi,

How can I calculate direction of a standing still vehicle?
I'm using getVelocity to find out direction while it's moving.
When velocity is 0 it does not give any direction.

I tried (wheel[0] + wheel[1] ) /2 - (wheel[2] + wheel[3] ) /2
but I could not find a method to calculate wheels' position.
I guess if I find a method to obtain wheels' position, the code above will work.

Thanks in advance.

#1
09/23/2005 (7:00 am)
I find a way to get direction of a vehicle.

But still having problem with collision detection. gServerContainer.collideBox or gServerContainer.castRay does not work even vehicle
collision is obvious.

Is there any better way to detect other vehicles ahead instead of using castRay or collideBox ?

Thanks


Point3F AIWheeledVehicle::getVehicleDirection()
{
WheeledVehicleData *vd= (WheeledVehicleData*) getDataBlock();
AssertFatal((getWheelCount() == 4), "AIWheeledVehicle must have 4 tires !!!" );
// Direction vector
// starts from middle of rear wheels
// ends at the middle of front wheels
// 0. and 1. tires are front tires
// 2. and 3. tires are rear tires
Point3F localDir = // Direction in the local space
(vd->wheel[0].pos + vd->wheel[1].pos) / 2 -
(vd->wheel[2].pos + vd->wheel[3].pos) / 2;

Point3F worldDir; // Direction in the world space
// Translate position to the world space
mObjToWorld.mulP(localDir, &worldDir);
worldDir.normalizeSafe();
//Con::printf("getVehicleDirection = [%f, %f, %f]", worldDir.x, worldDir.y, worldDir.z);
return worldDir;
}
#2
09/23/2005 (7:21 am)
The easiest way to find the direction is to pull it out of the objects Transform.

Get the transform. then use getColumn() to pull out the Y axis...this would
be column "1" (0=x,1=y,2=z,3=position).

Column "1" is where this objects local Y axis (local forward) faces in world space,
ie...the information your looking for.
#3
09/23/2005 (10:26 am)
In script, i believe it goes like.

$pie = objectname/number.getTransform();
$pie2 = $pie.getColumn(1); <-- I think.

For my vehicle collision setup, i'm using raycasts,about 5 feet infront of the vehicle. If it detects a interior, it will turn away from the vehicle using GetSteeringAngle and SetSteeringAngle. I'm having issues with schedule's though, i crashes my game. I posted the code in the TGE Public-> Mods if your interested.
#4
09/23/2005 (4:30 pm)
GetForwardVector(); -- it returns the Y column of the transform matrix like paul suggested and works in script or c++
#5
09/25/2005 (3:17 am)
Thanks you all to Paul, Chris, and Matt.
I already solved the problem.