This setup should be straightforward but I'm running out of ideas on what could be going wrong does anyone have any ideas? I'm fairly certain my code is executing correctly unless I've made a major accident somewhere and haven't realised as I've just been following tutorials on getting the agents to move along a path and most of them use the same code so I suspect it might be my setup that's the issue.



By the way I was doing some double checking on the hierarchy but I get the same results whether or not I place the agent I want to move as a child of the navmeshinstance or not. I'll post some pseudo code, one thing I've noticed is that even if I place the agent really high above the floor it does actually move downwards and I think it might be matching the height of the patrol path node I've setup so maybe I've done something daft with the directions? Now I'm not so sure the more I think about it.

func _physics_process(delta):
	
	if isWalking == true:
		animationPlayer.play("Droid_Walk_Pistol")
	
	if hasDetectedPlayer == true:
		ChangeDroidLightColourYellow()
		
	if hasDetectedPlayer == false:
		ChangeDroidLightColourCyan()
	
	for coneOfVisionRaycast in coneOfVisionRaycasts:
		if coneOfVisionRaycast.is_colliding():
			raycastCollision = coneOfVisionRaycast.get_collider()
			if raycastCollision.is_in_group("Player") and hasDetectedPlayer == false:
				hasDetectedPlayer = true
				
				
	if pathNode < path.size():
		var direction = (path[pathNode] - global_transform.origin)
		if direction.length() < 1:
			pathNode += 1
		else:
			move_and_slide(direction.normalized() * speed, Vector3.UP)
			
func MoveTo (targetPosition):
	look_at(patrolPath1.global_transform.origin, Vector3.UP)
	isIdle = false
	isWalking = true
	path = navMeshData.get_simple_path(global_transform.origin, targetPosition)
	pathNode = 0

func _on_Timer_timeout():
	MoveTo(patrolPath1.global_transform.origin)

In fact, now I'm playing with the agent more and putting it at odd angles above the patrol path it is matching up directly to the Y position of the node, how the hell have I done that?

Okay, definitely have a better understanding of the problem now, the droid I made just walks down in mid air to match the height of the patrol path and then stops, I think it might be somehow walking on the wrong axis?


I have my suspicions glancing down and finding one comment that it is indeed something to do with the agents moving along the Y axis to match up with the patrol path's height, I'll try a different tutorials' code and see if that makes a difference.

Now that's really frustrating, got the same results with a different tutorial so I wouldn't be surprised if something was going on with my setup.

Bumping a bit if it's okay, would be nice to see if we could find out what's going on, as near as I can work out the agent is perfectly moving along the Y axis to meet the height of my patrol path node and then it stops moving and won't move along the X and Z axis.

Ah, well I managed to solve the problem of it sinking into the ground at least, I hadn't set up the collision properly for my droid.

I did some more digging and it looks like I've found out the maths behind the problem, I suspect it might have something to do with how the velocity is being calculated because the direction doesn't seem to be returning correctly somehow and it's always returning on the Y axis * speed. I double checked this changing the speed and yep, it's just going down constantly which explains why this problem is happening and because the agent never reaches the destination it won't stop either.

The interesting thing is, this happens with both tutorials I've tried and I'm really just following along so I have no idea why this would be the case.

Sorry for my thought process completely leaking out onto the forum guys but you won't believe it I solved the problem after finding the solution buried away in a comment on something like the 5th tutorial I found on the same topic.

In case anyone has issues with enemies moving like I did, set direction.y = 0 in the physics process, before if direction.length() < 1:
For some reason, the enemies would get stuck and when I looked at the remote path dictionary, the y axis was = 0.4, so it seemed to be wanting to move into the ground mesh and couldn't.

The pathfinding is now working fine but I'm worried this is a bit of a hacky solution since all that's happening is you're potentially forcing the agent to go to the correct height? If someone could let me know what's going on in detail that would be good.

2 months later

I just managed to solve both the problems that I was experiencing with the navmesh, hurray! The first problem was I was experiencing strange sliding behaviour when my agent stopped and sometimes it would carry on infinitely. It turns out that was to do with the linear velocity. If you change the damp setting you can get rid of this problem I set it to -1 and the sliding behaviour stopped.

The second issue was the sinking behaviour which was incredibly frustrating, it turns out this was being caused by the collision shape being too high up and that is why half the model was sinking into the floor after stopping. The fix I found was only temporary while it was moving but this seems to be the main cause. Moving the collision shape further down into the ground instantly solved the problem.

Hope this helps anyone who runs into the same problems as me getting the 3.5 agents setup properly. I believe the specific maths behind the sinking is probably whatever is happening in the background between the agent height, the height offset and the position on the collision shape as well as the scale. It just hadn't tweaked for me that moving the collision shape down would change where the agent is positioned on the ground.

Just as an extra note on this issue, I think I'll keep the movement collision on one layer then make a separate collision shape for the agent mesh itself so as to keep the movement as accurate as possible while having collision accuracy for all other interactions.