Vehicle Steering

Blitz3D Forums/Blitz3D Programming/Vehicle Steering

EmerGki(Posted 2007) [#1]
Hi Guys...

I'm trying to do an AI for a Racing game, but, I'm using the ODE Physics for the vehicles... So, I need to do the vehicle steer to the next Waypoint (The steer# value are between -1 and 1 (-1 = Full left and 1 = Full Right)), How I do this?


IPete2(Posted 2007) [#2]
EmerGki,

This has been answered before and I am pretty certain there will be code in the archives to help you. Try a search for waypoints, there is also a demo in the 3d samples which came with B3D I think.

Anyway depending on what you are looking for, one way to achieve this would be to set up a bank and poke position data into it on a regular basis as you do a test drive around the track. Then read this data back and get your ai vehicle to search for the data from the bank and position the vehicle accordingly.

You could do several versions of this for inside track/outside track/ middle track. Then move between them as needed.

IPete2.


_PJ_(Posted 2007) [#3]
I would certainly use more than one version for where the car is in relation to the waypoint, else it [the AI] could try cutting corners etc.

With the J-ODE demo there is a car driving demonstration. I'm assuming your car will attempt to drive around the track in one continuous direction, therefore, maybe it might work better to have a simulated 'best-driving-line' which the car tries to follow instead of just between waypoints?

This way, the steering will be modified exponentially according to how far off the best-line it is?


EmerGki(Posted 2007) [#4]
Hi, I'm only just to know how many the AI need to Steer to point the car to the next waypoint... For the following waypoints (without steer) I have working a long time, but, now I need to do the vehicle wheels steer for each waypoint, I've no idea to do a 'best line' code... So, this is the motive what I'm using waypoints...

I need to steer only the wheels...

Thanks!!! ;)


IPete2(Posted 2007) [#5]
EmerGki,

Aha ! I think I see what you mean, the vehicles already move towards the waypoints, and now you need the steering to rotate the wheels to face the direction they are going to steer in so it is more realistic?

You need Pythagoras I think. You need the angle to turn the wheels the correct amount.

You know the position of the wheel you know the waypoint position, you know how far it is to the right angle (it is the same as the distance to the waypoint on that axis) - you need to calculate the angle on the hypotenuse (I think) and rotate your wheel to that angle.

Think of it in 2d for now:

You know the x and z position of the wheel
You know the x and z position of the waypoint
You know one angle is 90 degrees

x = wheel x subtracted from the waypoint x
y = wheel z subtracted from the waypoint z

radians=atan2(y,x)

rotation = radians * 180/Pi

(btw Pi = 3.14589)

Thats it in pseudo Flash code - I hope it is enough to get you onto the right track (sorry about the pun!).

IPete2.


EmerGki(Posted 2007) [#6]
Thank you IPete2, I'll Try this!!! =D .


Stevie G(Posted 2007) [#7]
Something like this should work. What you want to do is only turn the wheels if the angle to the next waypoint is greater than some threshold ( 5 degree in this case ) .. otherwise you may be jittering when the angle is low.

Assuming you have a Chassis Mesh or front axle pivot and a Waypoint pivot you can use deltayaw to find the angle difference without using the above. You should obviously limit the SteerDirection.

It'll take a lot of fiddling to get right though as I'm sure you'll find out.

AngleToTurn# = Deltayaw( Chassis , WaypointPivot )
SteerDirection# = 0
If ABS( AngleToTurn ) > 5 
     If ABS( AngleToTurn ) > 1
         SteerDirection = SGN( AngleToTurn )
    else
         SteerDirection = AngleToTurn
    endif
endif


Stevie


EmerGki(Posted 2007) [#8]
Hi Stevie!!! Is Exactly this!!!! Thanks a lot!!!


IPete2(Posted 2007) [#9]
Stevie,

Nice one dude - don't you just love this community sometimes...

IPete2.


puki(Posted 2007) [#10]
Right, let's see if anyone will cough-up the code for a GTA 3 clone.

I beg the community - in the name of love - hand it over.

Media too - cars and stuff - buildings - people.


_PJ_(Posted 2007) [#11]
Sorry, I misread your request!

Glad you got it sorted though!!!

And "puki" Sure thing. I'l start now and finish by 2103! Actually that's a lie, my blitz stuff is never finished.

Uunless you want a GTA clone text adventure? It says "Hello World" and if you press a key, it repeats itself!!!!