Jump to content
Site Stability Read more... ×
  • Advertisement
Sign in to follow this  
  • entry
    1
  • comments
    2
  • views
    323

About this blog

Blog for development of SPAACE, a tower defence space station builder game.

Entries in this blog

 

Unit Movement: The "Turning Circles" Approach

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). 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.   And here's a clip of the movement in action.   Desktop 2019.09.20 - 09.06.34.05_Trim.mp4 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. Desktop 2019.09.20 - 10.31.43.06_Trim.mp4 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?  

Danzabarr

Danzabarr

Sign in to follow this  
  • 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!