Raycast weird behavior

Hi.
I’m using the platformer template to play around a bit with raycasting. I replaced the sprite and collider of player with simple rectangle, and added one raycaster.

When moving with the player, it seems like the raycast lines are lagging behind the player.


(yellow lines are player’s (grey rectangle) movement. You can see that the raycast red lines are drawn according to the position that the player was like a frame (or couple of frames) before)

And one weird thing, when moving against the wall, the rays stops at the point where player would be, if there was no wall.


(on the left I’m moving against the wall, on the right I’m standing still)

I suppose this has something to do with the messaging system and the order of calculations?
Would there be a way to fix these issues?

That’s right. There is going to be a one frame discrepancy in the ray casts. I don’t think there’s anything that can be done about it right now. Correct @JCash?

Can you post the raycast code you are using? There should be immediate raycasts possible depending on which version of the function you are using.

physics.raycast_async() delayed

physics.raycast() immediate results

1 Like

Hi @Denis347!
You do not mention which raycast method you used.
As @pkeod pointed out, we have two versions. One of which is asynchronous, which also means that it returns the results after the scripts’ update functions has run.

1 Like