# How do I generate straight line path from A* path.

This topic is 4844 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I've written game that use A* to calculate shortest path between two points in my two-dimension grid game,i can do this.But the path I get isn't the straight line (A* used for find shortest path,not the straight path) so my agent move queerness. So,I think I should use the straight-path because it make my agent look good when it move but I don't know how to do this.And I think it very difficult. Anyone who has ever done this,help me please.Or give me the advice for generate the straight-line-path from A* path. What algorithms should I use??? Thank you very much. Dong.

##### Share on other sites
If the shortest path aint a straight line, why do you want it to be??
but you could smooth the resulting path, by using splines if you dont like a jagged kind of movement.

##### Share on other sites
Assuming I understand your problem, one method for doing what you want is to examine each node in turn, and if there is a straight unobstructed line from the previous node to the next node, remove this node from the path.

But that will involve moving in such a way that you do not always remain aligned to the grid. Is that permissible in your system?

##### Share on other sites
You could change the weights in your pathing to consider a straighter line shorter. Perhaps you could subtract some distance from all blocks based on there distance from the straight line to the goal. You might get your AI moving some extra spaces here and there but it will probably look more natural.

In an empty space there will be several "shortest" paths instead of taking the first one you could check them all and select the straightest one.

Possibly the simplest method would be to use a simpler pathing algorithm first to check if there is a straight line to the goal. if there is, take it, if there isn't use A*.

I hope some of that helps...

1. 1
2. 2
Rutin
13
3. 3
4. 4
5. 5

• 9
• 9
• 14
• 12
• 10
• ### Forum Statistics

• Total Topics
633260
• Total Posts
3011125
• ### Who's Online (See full list)

There are no registered users currently online

×

## Important Information

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!