Weird raycast behaviour

Godot Version

v4.2.1.stable.mono.official [b09f793f5]

Question

Hi there, linked is a video of a weird instance of raycast behaviour. What you’re seeing is the enemy tracking the player’s position via a raycast, but from time to time the raycast arrow turns blue and causes the enemy to switch into their “idle” state, which should only happen if they do not detect the player’s rigidbody.

The pathfinding for moving towards the player is updated every 1 second, but I have no idea why that is causing the issue as the two should be separate by all accounts. Changing it to update every frame fixes the issue, which is also puzzling me.

At the end of the day, keeping it per-frame is not an issue here. I’m more just curious now about what’s causing this to happen, if anyone knows.

Add debug visuals for the global positions that you are feeding into the navigation agent or tracking with your raycasts.

Since the debug path disappears for seconds something in your script logic is causing the navigation path to be considered finished.

So the most likely cause is that the raycast position of the “player” tracking is off or some if block in your movement script takes the wrong turn.