Saturday, October 28, 2017

c# - How to make my characters turn smoothy while walking on a path(list of coordinates)?


I have a list with coordinates - output from A* algorithm - and I would like to make my characters smoothly follow this path with rotations.


So I have something like A and I want to get C



enter image description here


How can I do this ?


EDIT


To make myself a little bit more clear:


I am more interested in smooth turning as I already know how to walk from one node to another.


EDIT


As many people find this useful (me too) I am posting link to Daniel Shiffman's "Nature of code" where he discusses a lot of game AI (and physics) problems e.g. steering behaviours http://natureofcode.com/book/chapter-6-autonomous-agents/#chapter06_section8



Answer



If you want smooth paths in a tile-based environment, there's no way around applying some path-smoothing on your A* waypoints. In his book about programming game A.I., Matt Buckland describes a simple and fast algorithm to smooth a path (basically remove all edges that can be removed without causing an intersection with your obstacles).


Once you have remove unnecessary edges like this, your first case (A -> B) is solved. Smoothing out the edges in your graph could be accomplished in several ways. Most likely, Hermite splines would work (depending a bit on your obstacle density and tile-size). Another option could be steering behaviors, where you start to steer towards the next waypoint, as soon as you're half a tile away from the current target (this really depends on how fast your "agent" moves/turns).



No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...