Seek Steering Behavior with Target Direction for Group of Fighters

I am implementing steering algorithms with group management for spaceships (fighters). I select a leader and assign the target positions for the other spaceships based on the target position of the leader and an offset. This works well. But when my spaceships arrive they all have a different direction. I want them to keep to look in the same direction (target - start).

I also want to combine this behavior with a minimum turning radius that is based on the speed. The only idea I have is to calculate a path for each spaceship with an point before the target position, so the ships have some time left to turn into the right position. But I dont know if this is a good idea. I guess there will be a lot of rare cases where this can cause a problem.

So the question is, if anybody knows how to solve this problem and has some (simple code) or pseudocode for me or at least some good explanation.

• Aug 1, 2013 at 12:58
• I think it is not a duplication. I already use some of the approaches that are mentioned in the other questions and I do not care about collisions within the formation (spaceships are small and there is a lot of space in space). Aug 1, 2013 at 20:52
• So this doesn't answer the question? Aug 1, 2013 at 21:11
• Not really, I tried this approach before, but there is no guarantee that the units will look to the right direction. They arrive at the point and then sometimes move around a little bit until they find their final position. This does not look very good in my case. I think it is similar to this problem http://www.gamasutra.com/view/feature/131505/toward_more_realistic_pathfinding.php?page=4, and I also would like to have a dynamic minimum turning radius at a later point. Aug 1, 2013 at 21:32
• OK. I think that the minimum steering radius (do spaceships have a minimum turn radius?) is just part of the implementation that goes with the overall implementation of adding arrival and flocking behaviour. Aug 1, 2013 at 21:45

Assuming this is a 2D game, then I read something in Game Coding Complete that may be of interest.

What you need to know is the point you are trying to steer toward (such as a point behind the "leader" of the squadron or an enemy fighter's location), the fighter's current position, and a unit vector (2D vector with a length of 1) pointing 90 degrees to the right of the space ships current heading. This is commonly referred to as the "right vector."

Next, calculate the unit vector that points from the fighter's current location to its target location. Note that it's very important that both the right vector and the vector pointing toward the target location have a length of 1 (floating point inaccuracies like 0.99999997 or 1.00000002 are fine), otherwise the next step won't work.

Next, calculate the dot product of the two vectors like this:

Dot_Product = (VecA.X * VecB.X) + (VecA.Y * VecB.Y)


If the dot product is less than zero, then the target location is to the fighter's left. If the dot product is greater than zero, then the target location is to the fighter's right. If the dot product is zero, or close to it, then the target location is directly in front of or directly behind the fighter.

You can steer you fighter according to this. Note that a greater speed will result in a larger turn radius, assuming you turn at the same rate, in degrees per second, regardless of velocity.

This solution takes advantage of an interesting property of the dot products of unit vectors (2D or 3D). The closer to pointing in the same direction the two vectors are, the closer to 1 the dot product gets. The closer to pointing in the opposite direction the two vectors are, the closer to -1 the dot product gets. If the dot product is zero, the vectors are at a right angle to each other.