Game Development Community

Vehicles

by Thomas Glennow · in RTS Starter Kit · 01/02/2005 (11:55 am) · 4 replies

I've just started scripting vehicle-like movement for units (i.e. they have to move to be able to turn) but I wanted to check if anyone else has done it before so as to not duplicate work, and if anyone has any ideas as to how to implement it.

Right now I'm starting with a dot product of the current unit facing and the vector of the target location to establish which way to turn, and I'm trying to figure out how to actually move and turn the unit the right way.

#1
01/02/2005 (12:18 pm)
As far as I am aware, "normal" RTS Units already turn to face the direction of their move-to point. You may want to take a look at how things are done in RTSUnit.cc, processTick(), specifically the movement portion (which is first IIRC). There are comments which briefly mention "turn the right direction", etc.
#2
01/02/2005 (12:37 pm)
Ah, sorry, I should've worded it more precisely. When I said turn the unit I meant the actual control of the angle of the vector so that it ends up somewhere between the current facing and the target's vector.

Basically what I'm thinking is to iterate the angle each loop, so it moves forward and slightly to one side, until it faces the target.
#3
01/02/2005 (12:43 pm)
You could still use the same area of code, just don't allow it to instantly turn the entire angle. Instead, have it turn your "max turn angle per tick" (remember a tick is 32 milliseconds), and that combined with the normal "move to location" processing should give you a good point to start from.

EDIT: You would need to modify the vector of travel per tick to only go in the direction the vehicle is currently facing, which might be a bit more work, but certainly doable if you have a basic understanding of vector math.
#4
01/02/2005 (4:33 pm)
Keep in mind that both the server and the client have to simulate the same thing, or you will get a lot of jumping around. In other words, don't change a units destination, just how gets there, or you will need to send updated info about the movement event.