Thunder2002

Hi guys,

i am thinking about the way how to move and position and also rotate a unit on terrain in a RTS game. First of all my actual point where i am:

I have a quadtree terrain engine that can give me back any interpolated height value by giving it the X and Y(will be the 3D Z coord) coords. So i can move a unit around and adjust the Y axis value of the unit so that it will not drown or fly over the terrain. Next i calculated the angle using pythagoream by using the X and Y(Z axis in 3D space again) movement (from a top down view) in which the unit is moving. So there is not at least any smooth rotation animation or so but some basic stuff.

I think the next step is rotating the unit also along the X and Z axis in 3D space. Therefore a thought of 4 vectors in world coords at the 4 bounding corners of my unit, then i want to get the height from the terrain at this points. After that i would like to calculate 2 angles for the X and 2 for the Z axis rotation and get and average value.

I think this is not really easy and at least the very often needed transformation of vector coords from unit projection coords to world coords gets me totally crazy so that i can't get an idea how to calculate that stuff anymore

Hopefully someone can give me some advice and/or practical used sample for that.

Greets Thunder2002


Re: XNA Game Studio Express RTS unit movement and positioning including rotations

waruwaru

If the unit has a bounding box/cube, it should be easy to find the center point of the box (or if you turrent is not in the center, adjust appropriately).

Find the same point (or where the turret should aim) on the enemy

imagine a vector from 1st point to 2nd point, that is where the turret should be pointing. Unless you are on a really sharp inclined surface, this should be good enough If you are on inclined surface, you might want to keep the displacement of the turret (relative to the unit), and move/rotate with the unit.






Re: XNA Game Studio Express RTS unit movement and positioning including rotations

Thunder2002

But i dont always have an enemy. So i dont have a point in 3d space to let my unit look at. Also if I imagine that i will have an enemy for my unit, they can both be at the same height on the terrain but at different positions with hills etc. between them. So if my unit is driving up a hill i cant just point to and enemy anymore, it needs to look up into the sky.

Here is just a very basic shape of what i am thinking of: http://www.thunder-development.de/test/unit_on_terrain_hills.png

Lets think the axis in 3d space into the depth is here Z (up and down is Y and left to right is X). So if the red square is our unit, i need to rotate it along the Z axis to fit on the terrain. But how to do that !





Re: XNA Game Studio Express RTS unit movement and positioning including rotations

waruwaru

Thunder2002 wrote:
But i dont always have an enemy. So i dont have a point in 3d space to let my unit look at. Also if I imagine that i will have an enemy for my unit, they can both be at the same height on the terrain but at different positions with hills etc. between them. So if my unit is driving up a hill i cant just point to and enemy anymore, it needs to look up into the sky.

Lets pretend the base of the turret is at the origin. Forget the tank for a second

If there isn't anything to point at, have it point at a default direction. Either the prvious direction the turret is pointing at, or same direction as the tank's moving direction would work.

If there is something to point at, point that direction.

Set a minimum up/down (I think you call it Y axis). So if the turret's pointing down passing the minimum, set the up/down value to the minimum. (well, the directional vector should be normalized before compare)

After you get the turret to point correctly, you can transpose it to the proper location on the tank, and rotate it with the tank, and transpose your tank onto the map.

If you don't ever want to point at the hill in front of you, then you would have to figure out if there is something in front of you and turn the turret away. I am not sure if that kind of accuracy will get you any gameplay benefit.


Here is just a very basic shape of what i am thinking of: http://www.thunder-development.de/test/unit_on_terrain_hills.png

Lets think the axis in 3d space into the depth is here Z (up and down is Y and left to right is X). So if the red square is our unit, i need to rotate it along the Z axis to fit on the terrain. But how to do that !