I have my units that i move around my map with path finding. The units can move in 8 directions, currently i have the units moving around the map with a extremely basic check against the unit's current position vs. the next target destination in an array of Vector2s (the path). However, the movement is rather jagged and not very fluid.

Current code (I know its not very good, i did this just to test out the pathfinding really);

 if (Position.X < Path [CurrentPathPoint].X) {
     SpeedDir.X = 1;
 if (Position.X > Path [CurrentPathPoint].X) {
     SpeedDir.X = -1;
 if (Position.Y < Path [CurrentPathPoint].Y) {
     SpeedDir.Y = 1;
 if (Position.Y > Path [CurrentPathPoint].Y) {
     SpeedDir.Y = -1;

 Position += SpeedDir * Speed;

I should mention that im not looking for any sort of rotational movement, just smooth diagonal and directional movement. However, i'm at a lose on how i can achieve that... So any help greatly appreciated :)!

Edit: Smooth Transitioning between movements is what i'm looking for. Right now, the units sometimes (not sure how to describe but they "stutter" along), looks like they are shaking when moving. As to what i tried before, i had the position being updated directly in the If statements, that didn't give me any stuttering but did not seem like a good approach so i changed to the one above.

  • \$\begingroup\$ Smooth in what way? Over time or smoothing transitioning between movements? What have you tried to do to make the movement smooth? Please edit your question to include this information. \$\endgroup\$
    – House
    Commented Jul 12, 2013 at 19:54
  • \$\begingroup\$ Simple approach, but probably not the best: use Vector2.CatmullRom \$\endgroup\$ Commented Jul 12, 2013 at 20:05

1 Answer 1


Implement acceleration. Don't modify the velocity directly, let the acceleration change your velocity over time. This will make the movement appear more natural and smooth, because it's close to how things work in real life.

With the changes the pathfinding will change the acceleration value. In turn, the velocity will be adjusted smoothly from one vector to the next by changing over time.

You may want to also include some friction into the equation. This way, when you're going forward, then start applying force to go right, you won't forever continue to go forward too.

For stopping you can do a little bit of steering type behavior to come to a stop.

If you're not wanting "free movement" of the unit, this probably isn't the solution for you. It's going to be very difficult to make orthogonal/diagonal-only movement look natural and smooth between transitions because nothing in the real world moves like that.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .