Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3.5b1 navigation agent seems to sometimes bump around an obstacle in a way that feels like a bug #57486

Closed
BigZaphod opened this issue Jan 31, 2022 · 7 comments · Fixed by #61619

Comments

@BigZaphod
Copy link

BigZaphod commented Jan 31, 2022

I tried throwing together a very simple test of the navigation with an obstacle in the 3.5b1 build and it seems to behave oddly with the agent sometimes jumping or bumping as if it hit something. I can't tell if I've set this up wrong or am missing something or not, but I assume this isn't expected behavior? I used the blog post as a guide to configuring the agent and obstacle, but I can't rule out that I did something stupid here.

Godot3.5NavTest.mov

The scene tree looks like this:

image

And this is the only script (attached to the player):

extends RigidBody2D

var speed = 100

func _ready():
	$NavigationAgent2D.set_target_location(Vector2(0,0))


func _physics_process(delta):
	if $NavigationAgent2D.is_navigation_finished():
		linear_velocity = Vector2.ZERO
	else:
		var target = $NavigationAgent2D.get_next_location()
		var vel = global_position.direction_to(target) * speed
		$NavigationAgent2D.set_velocity(vel)


func _on_NavigationAgent2D_velocity_computed(safe_velocity):
	linear_velocity = safe_velocity

Full project:
Godot3.5NavTest.zip

Originally posted by @BigZaphod in #48395 (comment)

@Scony
Copy link
Contributor

Scony commented Jan 31, 2022

@BigZaphod the behavior on the video you attached is normal - this is how it looks like when small-radius agent avoids big-radius obstacle.

What do you mean by jumping and bumping? Is that smth else than what one can see on the video?

@BigZaphod
Copy link
Author

The video is basically what I was seeing - the results seem to depend a lot on where the obstacles are in relation to each other and sometimes the agent acts like it hits an invisible wall pretty far out from where the obstacle actually is. I guess if that's expected behavior then that's fine, but the sudden velocity change feels so jarring that I assumed it was a bug. Are there ways to mitigate this sort of thing? (And if there are, perhaps it could be fodder for the eventual documentation?)

@Scony
Copy link
Contributor

Scony commented Jan 31, 2022

hits an invisible wall

by default obstacle's radius is estimated from collision shape - as for rectangle, the resulting radius will be big enough to include your rectangular collision shape inside the circle it creates. This leads to the obstacle radius being too big around the corners. You can disable estimation and set something smaller to work around that effect. Also, you can increase agent's time horizon.

@nathanielhudson
Copy link

nathanielhudson commented Apr 27, 2022

FWIW I just tried this project in 3.5b4.

The pathing looks better - it takes the shorter path around the right of the object instead of the left, and doesn't "suddenly" notice the obstacle anymore. One thing that does still seem to be an issue is that the mob's speed isn't constant, and I'm not sure why. The speed being passed in to $NavigationAgent2D.set_velocity is a constant 100, but the magnitude of safe_velocity sent back to _on_NavigationAgent2D_velocity_computed ranges from 100 to 85-ish. I'm not sure why, especially given that the obstacle is static. You can see this by using OP's project, but adjusting _on_NavigationAgent2D_velocity_computed:

func _on_NavigationAgent2D_velocity_computed(safe_velocity):
	linear_velocity = safe_velocity
	print(round(linear_velocity.length()))

Anything I'm missing?

@smix8
Copy link
Contributor

smix8 commented May 21, 2022

The speed is not constant cause the RVO avoidance is a number of circles that apply different forces pushing agents in directions and not a perfect "this is your new path highway" calculation were the agent can run along at maximum speed.

For maximum speed you need to not used the avoidance for (static) objects at all. Instead, bake your navmesh or update your navigationpolygon so the agent is aware of the scene geometry at high detail.

The obstacle avoidance is a last resort intended for objects that are constantly moving as it would be too performance costly in many cases to bake them into a navigationmesh every frame.

@nathanielhudson
Copy link

nathanielhudson commented May 25, 2022

Ah, I see. Thank you for your reply!

(I'm not the issue OP, but I wonder if this should be closed since everything seems to be working as expected)

@smix8
Copy link
Contributor

smix8 commented May 25, 2022

It is still open cause, while the current 3.5 navigation documentation "exists", it still misses a lot of information like this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants