# Pathfinding and update\_vel!

**URL:** https://discourse.julialang.org/t/pathfinding-and-update-vel/87471
**Category:** Modelling & Simulations
**Tags:** agents
**Created:** [September 19, 2022, 2:51pm UTC](https://discourse.julialang.org/t/pathfinding-and-update-vel/87471 "2022-09-19T14:51:56Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![InesP](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/inesp/32/42792_2.png) [@InesP](https://discourse.julialang.org/u/InesP)
#### Post date: [September 19, 2022, 2:51pm UTC](https://discourse.julialang.org/t/pathfinding-and-update-vel/87471/1 "2022-09-19T14:51:56Z")

</div>

Hey,

I started using Agents.jl recently, and I have a question regarding using pathfinding and update\_vel! together.

I’m trying to use Agents to model crowd dynamics in emergency situations. Right now, I’m using the AStar function in order for the agents to find the best exit of a building, thus, instead of move\_agent!, I’m using move\_along\_route!. However, this implementation thus does not have into account social forces, for instance, that agents usually adjust their speed to maintain a certain distance from other agents or even collisions. Since Agents has an elastic\_collision! function, I decided to use it just to see how it would impact my model, however, from the videos I made it seems that it has no impact and the agents just follow the route from AStar. I also tried to update the vel field in order for agents to preserve a certain distance from each other, but once again they just followed the route from AStar.

Is it possible that I’m doing something wrong, or is it just not possible yet to update the vel field when using move\_along\_route!? Do you have any suggestions on the best way for me to implement this?

Thank you so much in advance 😊

---

<div class="post-metadata">

### Author: ![Datseris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/datseris/32/13406_2.png) [@Datseris](https://discourse.julialang.org/u/Datseris)
#### Post date: [September 19, 2022, 3:04pm UTC](https://discourse.julialang.org/t/pathfinding-and-update-vel/87471/2 "2022-09-19T15:04:36Z")

</div>

Hello!

cc @cryptic.ax

> [@InesP](#):
>
> Since Agents has an elastic\_collision! function, I decided to use it just to see how it would impact my model

I don’t think that would play well with `move_along_route!`… I have to be honest, I am not sure how alternations in agent position and velocity mess with `move_along_route!`. The typical scenario is that you need to re-create a route if you alter them, but perhaps there are cases where you don’t have to. I’ll wait for the developer of the pathfinding (@cryptic.ax ) to comment on that.

> [@InesP](#):
>
> Do you have any suggestions on the best way for me to implement this?

There was an open PR here [add Force Based Motion Planning (FMP) by rmcsqrd · Pull Request #456 · JuliaDynamics/Agents.jl · GitHub](https://github.com/JuliaDynamics/Agents.jl/pull/456) on force based motion. I am not sure how related that would be for social forces. We would for sure like to have some functionality in Agents.jl for social forces, as I have seen people ask this before numerous times. But this would be a formal submodule that would take effort from someone to implement 🙂

What code do you have now for social forces? Can you create a **Minimal Working Example** so that we have a common root to discuss on?

---

<div class="post-metadata">

### Author: ![cryptic.ax](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cryptic.ax/32/220540_2.png) [@cryptic.ax](https://discourse.julialang.org/u/cryptic.ax)
#### Post date: [September 21, 2022, 6:37pm UTC](https://discourse.julialang.org/t/pathfinding-and-update-vel/87471/3 "2022-09-21T18:37:45Z")

</div>

Hi!  
`AStar` directly sets the position of the agent, so it doesn’t really take into account `update_vel!` and the like. Instead, it directly accepts `speed` and `dt` to calculate how far the agent should move along the path.

What you _could_ do is move the agent according to the external forces _after_ calling `move_along_route!`. As long as the agent isn’t disrupted from its path too much, it will still follow the optimal or near-optimal path.

That said, Agents.jl would certainly benefit from more advanced pathfinding algorithms, such as FMP as @Datseris mentioned which (if I’m not wrong) is also useful for crowd dynamics simulations. Alternative algorithms (like D\*/D\* Lite, LPA\* etc.) are also welcome. Currently, the best way of simulating dynamic pathfinding is using a hierarchical approach: Use A\* on a coarse grid to find the approximate path to the end, and on a finer grid to find the best path between individual segments of the coarse path. There isn’t any functionality in the library that does this for you yet, but it should be possible with the current setup and PRs are always welcome.
