Pathed Ai Cars
by Quentin Headen · in Technical Issues · 01/26/2008 (3:14 pm) · 4 replies
How is it possible that a AiWheeled Vehicle can follow a path just like an Ai player? I want to make some opponents in my racing game. Please help me.
Thank you :)
Thank you :)
About the author
Just your average programmer who tries to finish the projects he starts. :) I am currently focused on creating games with Torque engines. My website is http://phaseshiftsoftware.com
#2
01/27/2008 (6:55 pm)
Thanks for the reply, but if I tell my car to setMoveDestination(%destination), I don't want it to always move at max speed. How can I make the car slow down a bit like when its going around a corner? I have setup some nodes and my car follows it, but when I make a curve, the car just flips over because it has the pedal to the metal. How can I slow it down a bit?
#3
01/28/2008 (12:34 pm)
Can't you use setMoveSpeed(%speed)? Just before/after setMoveDestination() where %sped is a value form 0-1.0 representing a percentage of each cars max speed. This might make it a bit harder to implement good driving if your cars have different speed/traction/mass per model because for each one the percentage would not be the same. But just for testing or if they all share a max speed, this should work.
#4
01/28/2008 (1:44 pm)
Thank you over, and over, and over, and over, and over to the millionth power for that answer. :) I have always wanted to use the setMoveSpeed() function, but I never got it to work because I didn't know the value had to be between 0 and 1. Thanks a lot Morrock, it worked.
Torque 3D Owner Morrock
In the C++ add some kind of DriveNode, with variables for whether it's a turn/straightway, what speed is optimal before reaching this node (so they can slow down on tight turns) and the next/previous nodes.
Then with the cars. Have each car find it's next node, if it's a straightaway node they just drive straight into it while accelerating to that nodes desiredSpeed. If it's a turn you can either place several nodes along each turn for them to aim for. Or set one midway through the turn and at the end. There are several equations for finding the curvature of a well, curve. Have the car travel along this at the nodes preset speeds. You could have each car at the beginning of the race assign itself variables that will be added/subtracted from each nodes preset speed, turn distance, etc... So they don't all just do a simple "follow the leader" on eachother.
There are obviously many other ways, and many ways where cars actually think for themselves, but this seems the easiest. What does everyone else think?
Edit: or were you asking if aiWheeledVehicles have a setDestination() function like aiPlayers? lol. Because if so, answers are here:tdn.garagegames.com/wiki/Torque_Console_Objects#AIWheeledVehicle