Skip to content

Commit

Permalink
Add new test case for disabling agent
Browse files Browse the repository at this point in the history
  • Loading branch information
Scony committed Dec 20, 2022
1 parent 53e25c4 commit 5da36c8
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
59 changes: 59 additions & 0 deletions tests/int/TestDetourCrowd.gd
Original file line number Diff line number Diff line change
Expand Up @@ -351,3 +351,62 @@ func test_agent_avoiding_agent():
crowd.update(0.55)
assert_almost_eq_v3(agent_1.position, Vector3(4.97, 0.2, -0.62))
assert_almost_eq_v3(agent_2.position, Vector3(5.02, 0.2, 0.62))


func test_agent_not_avoiding_disabled_agent():
# input:
var input_geometry = AdvancedNavigationServer3D.create_empty_input_geometry()
var plane_mesh = PlaneMesh.new()
plane_mesh.size = Vector2(100, 100)
input_geometry.add_resources([plane_mesh])

# config:
var recast_config = AdvancedNavigationServer3D.create_empty_recast_polygon_mesh_config()
var detour_config = AdvancedNavigationServer3D.create_empty_detour_navigation_mesh_config()
var crowd_config = AdvancedNavigationServer3D.create_empty_detour_crowd_config()

# navmesh:
var navmesh = AdvancedNavigationServer3D.create_empty_detour_navigation_mesh()
navmesh.build_from_input_geometry(input_geometry, recast_config, detour_config)

# crowd:
var crowd = navmesh.create_crowd(crowd_config)
var agent_1_config = AdvancedNavigationServer3D.create_empty_detour_crowd_agent_config()
agent_1_config.radius = 0.6
agent_1_config.max_acceleration = 0.6
agent_1_config.max_speed = 1.2
agent_1_config.collision_query_range = agent_1_config.radius * 8
agent_1_config.separation_weight = 0
var agent_2_config = AdvancedNavigationServer3D.create_empty_detour_crowd_agent_config()
agent_2_config.radius = 0.6
agent_2_config.max_acceleration = 0.6
agent_2_config.max_speed = 1.2
agent_2_config.collision_query_range = agent_2_config.radius * 8
agent_2_config.separation_weight = 0
var agent_1 = crowd.create_agent(Vector3(0, 0, 0), agent_1_config)
var agent_2 = crowd.create_agent(Vector3(5, 0, 0), agent_2_config)
assert_eq(agent_1.state, agent_1.STATE_WALKING)
assert_eq(agent_2.state, agent_1.STATE_WALKING)
assert_almost_eq_v3(agent_1.position, Vector3(0.0, 0.2, 0.0))
assert_almost_eq_v3(agent_2.position, Vector3(5.0, 0.2, 0.0))
assert_true(agent_1.set_target(Vector3(10, 0, 0)))
assert_true(agent_2.set_target(Vector3(0, 0, 0)))
agent_2.disable()
assert_eq(agent_2.state, agent_1.STATE_DISABLED)
crowd.update(1.0)
assert_almost_eq_v3(agent_1.position, Vector3(0.6, 0.2, 0.0))
assert_almost_eq_v3(agent_2.position, Vector3(5.0, 0.2, 0.0))
crowd.update(1.0)
assert_almost_eq_v3(agent_1.position, Vector3(1.8, 0.2, 0.0))
assert_almost_eq_v3(agent_2.position, Vector3(5.0, 0.2, 0.0))
crowd.update(1.0)
assert_almost_eq_v3(agent_1.position, Vector3(3.0, 0.2, 0.0))
assert_almost_eq_v3(agent_2.position, Vector3(5.0, 0.2, 0.0))
crowd.update(1.0)
assert_almost_eq_v3(agent_1.position, Vector3(4.2, 0.2, 0.0))
assert_almost_eq_v3(agent_2.position, Vector3(5.0, 0.2, 0.0))
crowd.update(0.3)
assert_almost_eq_v3(agent_1.position, Vector3(4.56, 0.2, 0.0))
assert_almost_eq_v3(agent_2.position, Vector3(5.0, 0.2, 0.0))
crowd.update(0.55)
assert_almost_eq_v3(agent_1.position, Vector3(5.22, 0.2, 0.0))

0 comments on commit 5da36c8

Please sign in to comment.