Jump to content
  • Advertisement
Sign in to follow this  
  • entry
    1
  • comments
    2
  • views
    443

Unit Movement: The "Turning Circles" Approach

Danzabarr

1160 views

Generally, units need to be responsive in real time games, like an RTS or FPS. That means instead of obeying the laws of physics, games often feature units that very quickly turn to face their target. Sometimes the rotation is immediate, sometimes there is some interpolation. The cost of spinning quickly, in terms of loss of realism, is less obvious when the unit is a tall, thin object like a humanoid figure, but more obvious when the units are large, like a really massive boss in an RPG, or long in the Z direction, like a quadrupedal animal, or a vehicle.

Since long spaceships could suffer quite a lot from this loss of realism, I decided to implement a different turning movement in SPAACE. However, I should say - I'm not looking to simulate realistic physics, there are a zillion things wrong with what I'm doing already. I just don't like the twitchy spinning around the Y Axis, or doubling back as if the object was some kind of boneless jellyfish. And in any case, why not treat unit responsiveness as a secondary unit stat, such as movement speed and attack range?

The solution I came up with was to have two imaginary 'turning circles', to the left and right of the unit position. The unit would move around the circumference of one of these circles (clockwise around the right circle, and anticlockwise around the left circle) until it reached the correct point of tangency from the target. I've drawn a diagram to describe this (angles not exactly accurate).

turning_circle_movement.thumb.JPG.eb15fd75ece6b8c4b607e42e5fecd7eb.JPG

Whether the unit moves around the left or the right circle is determined by choosing the shorter of the two dotted lines, which is the length around the circumference of the circle to the point of tangency, plus the length of the tangent to the target.

Of course any circle and point has two points of tangency, but it turns out it's always the first point (x1, y1) for the anti-clockwise, and the second point (x2, y2) for clockwise, which turns the unit smoothly onto the line towards the target. Here's another diagram which hopefully helps explain what I mean - I've included just the left circle to make it clearer.

turning_circle_movement2.thumb.JPG.07f68361970ec7c6a299aaf140fb7892.JPG

 

And here's a clip of the movement in action.

 

This works fairly well. Once the unit reaches its target, it can even loop back and around, in circles or figure-eights, as if it was an airplane or bird that has to continuously move forward to stay in flight. It also looks really cool as a bunch of aliens swarming a target.

Next, I wanted the ships to fly at the target, guns blazing, carry on for a little while in the opposite direction, then loop back around before starting another pass.

To achieve that, I simply specify a minimum tangent length, only choosing to turn around one of the circles if the tangent to the target is greater than the specified minimum, otherwise just fly straight.

Here's what that looks like.

You might also have noticed the turning circles changing in diameter... The units basically lerp to a tighter circle when they have an attack target.

Anyway, this is my first Dev Blog, I'm obviously already a fair way into the project, so I decided to revisit a feature I've already implemented to talk about. It would be interesting to hear what you think, or if you have come up with different solutions to unit movement, or perhaps if you know somewhere else this approach has been applied... maybe a boat/ship simulator?

 



2 Comments


Recommended Comments

Could you not just set a min forward speed whenever turning?

Share this comment


Link to comment
20 minutes ago, MGB said:

Could you not just set a min forward speed whenever turning?

Being the obvious solution, that was my first approach.

I found it less than ideal for a few reasons.

Main one was the unit has a tendency to do circles around the destination if the minimum turning angle / forward speed combination isn't tight enough

Share this comment


Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!