Game Development Community

Racing Direction

by DNADMG · in Torque Game Engine · 03/09/2006 (12:24 pm) · 7 replies

I am currenlty working on modifying the racing mod and have some direction issues.. i want the vehicle to only be able to advance down the track, and not be able to turn around.. since the track turns back on itself i cannot just limit the z rotation, so i have had to come up with another possible solution.. I have created a trigger that will set a forward direction reference variable everytime there is a turn in the track. Now what I cant exaclty figure out is how to compare this to the vehicle objects forward vector and restrict its movement.

So to recap:

...racing mod
... keep player moving in forward direction of turny track
...do I need to compare the two forward vectors in the script or in the engine to clamp?
... if engine where should I clamp its movement?
... if script - same .. where to clamp movement?

...am I going about this the wrong way?
...does any of this make sense?

thanks kind peoples..

#1
03/09/2006 (12:38 pm)
Also does anyone know if it is possible to set the forward vector of an object?
#2
03/09/2006 (12:48 pm)
I thnk using a forward direction reference is the way to go. But you should have triggers set up so there's a valid forward direction reference for every part of the track. Then all you need to do is use some kind of function which continuously reschedules itself and calculates the angle between the car forward vector and the direction reference vector, if the angle is too great set a global. when the function in the key bindings file calls $IncYaw or whatever, a condition should check whether this global has been set. you'd probably need two globals, for disabling left yaw and right yaw.
#3
03/09/2006 (12:54 pm)
So you are saying that i should just have the vehicle auto turn back in the forward direction when the angle between the two objects gets out of range?

is there a function built into tge that will compute the angle?

thanks for your help,
-a
#4
03/09/2006 (1:05 pm)
I don't think you should have it auto turn.(but it is YOUR game) Just something that will calculate the angle between the two vectors and if it's too big, disable the steering in that direction.

to find the angle, normalize the vectors and take the inverse cosine of the dot product of the two vectors.
#5
03/09/2006 (1:11 pm)
Ok .. i think this will work .. thanks for your help.
#6
03/09/2006 (2:01 pm)
Does getForwardVector() not return normalized values?
#7
03/09/2006 (3:00 pm)
I'm not sure. call it from the game console and see. if any of the components are greater than 1 then you know it's not normalized.