Game Development Community

dev|Pro Game Development Curriculum

Simple vehicles turn with left/right keys fix

by F.W. Hardijzer · 05/19/2003 (9:17 am) · 9 comments

vehicle.cc
in
void Vehicle::updateMove(const Move* move)
find
if (move != &NullMove) {
then comment out
F32 y = move->yaw;
mSteering.x = mClampF(mSteering.x + y,-mDataBlock->maxSteeringAngle,
                            mDataBlock->maxSteeringAngle);
and add
F32 y = move->x;
mSteering.x = move->x * mDataBlock->maxSteeringAngle;
voila... done

#1
05/19/2003 (5:01 pm)
Simple but sweet. :)
#2
05/20/2003 (2:11 am)
Great!
#3
05/24/2003 (2:21 pm)
I've made my own mod so the wheels don't turn that sudden (now its like press left key and the wheels are immediatly facing left)
If anyone is interrested, let me know :)
#4
06/19/2003 (12:48 pm)
Use this to make the wheels turn smoothly (change 0.5 to change the turn speed):

F32 x = move->x * mDataBlock->maxSteeringAngle;
mSteering.x = 0.5 * mSteering.x + (1.0-0.5) * x;
#5
08/04/2003 (7:31 am)
This also affects the steering of the flying vehicles. I liked the way I could fly around.... now my flyers can no longer roll on demand (used left and right for that)
#6
08/17/2006 (7:54 pm)
I'm a bit of a noob, but couldn't you add a variable to the flying objects and have an if statement to test if the variable is set to determine which version of the code is used?.
#7
08/17/2006 (9:41 pm)
Great code F.W. Hardijzer and Marcelo Oliveira, was a great help to a noob.

With a bit more code you can open this all up to the WheeledVehicleData datablock so you can change the setting in the cs file, delete the DSO files and then just open Torque to apply the settings without needing to recompile every time you want to change the speed the wheels turn at.

The following are the 5 steps I have made to my SDK engine and cs files to allow for ajustable steering without the need to recompile each time you ajust it.

###START - 001-Steer by keys.txt

1)Open up a variable to the scripting language
In "Vehicle.h"
Find
F32 maxSteeringAngle;
Insert following on next line.
F32 steeringIncrements;


2)Initialise the variable with a default.
In "Vehicle.cc"
Find
VehicleData::VehicleData()
Insert following on next line.
steeringIncrements = 0.5;


3)Amend the movement section to take keys to steer using the steeringIncrements variable.
In "Vehicle.cc"
Find
void Vehicle::updateMove(const Move* move)
In the function find and comment out
F32 y = move->yaw;
mSteering.x = mClampF(mSteering.x + y,-mDataBlock->maxSteeringAngle, mDataBlock->maxSteeringAngle);
Add the following on the next line.
F32 x = move->x * mDataBlock->maxSteeringAngle;
mSteering.x = mDataBlock->steeringIncrements * mSteering.x + (1.0-mDataBlock->steeringIncrements) * x;


4)Update variable from car.cs file datablock.
In "Vehicle.cc"
Find
void VehicleData::initPersistFields()
In the function find
addField("maxSteeringAngle", TypeF32, Offset(maxSteeringAngle, VehicleData));
Add the following on the next line.
addField("steeringIncrements", TypeF32, Offset(steeringIncrements, VehicleData));


5)Set the turn speed for the game to 0.5
Open "BaseDS\server\scripts\car.cs"
Find
datablock WheeledVehicleData(DefaultCar)
In the function find
maxSteeringAngle = 0.785;  // Maximum steering angle, should match animation
Add the following on the next line.
steeringIncrements = 0.9;  // Change between 0.1(turn fast) and 0.9(turn slow).

###END - 001-Steer by keys.txt
#8
01/03/2008 (5:22 am)
What I've seek! :-)
#9
04/11/2008 (3:59 pm)
Very useful. I've been trying to figure this out for a while. Thanks.