dodgy_2d
A Rust crate to compute local collision avoidance (specifically ORCA) for agents.
Why local collision avoidance?
Characters in video games generally need to find paths to navigate around the game world. Once this is done, the path needs to be followed. The trouble occurs when characters start getting in the way of each other. As paths are not generally regenerated every game frame, other characters cannot be taken into account. Local collision avoidance provides cheap avoidance for characters even in high-density situations.
Which local collision avoidance?
There are several algorithms for local collision avoidance. This crate implements ORCA.
This crate is essentially a port of RVO2 to Rust. Several changes have been made: tests have been written, code more commented, and the public API made more flexible.
Example
This example uses the "raw" API.
use Cow;
use ;
let mut agents: = vec!;
let goal_points = vec!;
let obstacles: = vec!;
let time_horizon = 3.0;
let obstacle_time_horizon = 1.0;
for i in 0..100
This is the preferred API to use, since finding neighbours is essentially just a spatial query. Often, finding related objects within some radius is performed anyway in most game engines. Using this API, neighbours can be found through your regular spatial queries, and exposes just the avoidance part.
However, an alternative using the Simulator
struct:
use ;
let mut simulator = new;
simulator.add_agent;
// Add more agents.
simulator.add_obstacle;
// Add more obstacles.
for i in 0..100
Again, this is not the preferred method! It is just a simpler way to get up and running for a small group of users. The other API is more flexible and preferred.
License
License under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
Attribution
dodgy_2d contains code ported from RVO2. See original_license.txt.