Hexarategy: Ship movements

Keywords: nice method, direction vector, burner effect, huge delta, ship, object, target, animation, stop, grid, unity. Powered by TextRank.

Tacked another core feature this evening, which is the movement of the ships around the grid. Thankfully Unity provides a nice method of moving object around. I’ll get to that but before this I tried doing stuff the old fashioned way, by calculating the direction vector between the source and target, and applying a translation vector with the delta time to move the object. This does work but it runs into 2 problems:

  1. the movements are jittery. The diagonal edges on the ship were re-rendering

giving a sort of escalator effect

  1. comparing vectors to know when to stop the animation is not nice because of

the huge delta you need to provide to the comparison. Which means that there is a snap effect after you consider the vectors equal, because you have to center the object on the target cell.

The best method is to use the Vector3.MoveTowards() method which guarantees that it will never overshoot. Now comparing vectors with a rather small epsilon works nicely and the stop / recenter animation look quite smooth. Here is what it looks like currently:


There are obvious things that need to be done, like the ship should follow the hex grids and not cut through diagonally. Also the ship needs to rotate in the direction that it needs to navigate. Also a nice after-burner effect would be cool when the ship is moving.


Similar posts

Powered by TF-IDF/Cosine similarity

First published on 2017-12-14

Generated on May 29, 2024, 10:01 PM


Mobile optimized version. Desktop version.