Raycast hits a non-existent bump between Tile colliders

:gear: Godot Version 4.2.1

This is my first topical post in my life, on any site, so I apologize in advance if I make any mistakes. Also, my native language is not English, so sorry if my sentence formulations are not correct.

Hi, I need your help please, I really don’t understand why I have the problem mentioned in the title.


Initial situation:

  • I created a very simple Tile Set with a physical layer
  • All collision box on tile are just a same simple square, where point are snap on corner of tiles
  • Added TileMap and use it to create simple walls and ground (Tile Size = 32 / 32)
  • I added a Raycast2D (with a Sprite2D as a child which is constantly positioned on the collision point for debugging)
  • Layer and mask collisions are same in Tile Map physic layer and Raycast
  • Raycast info is use in _physics_process()

What I tried (without success):

  • Increase and decrease Tile Size in Tile Map (to overlap or separate the edges of collisions)
  • Remove snap and increase and decrease collision shape on Tiles (to overlap or separate the edges of collisions too)
  • Erase and paint new tile on Tile Map after change collision shape


  • It seems to depend on the angle between the raycast and the contact normal (when ray hit walls (or almost) perpendicularly, no problems)
  • The raycast seems to tap between the lines and pushed back

Possible solution, which I haven’t tried yet (because ugly):

  • Detect the case where the error is occurring by comparing the normal of the contact and manually adding the missing distance
  • Use an area2D on the point of impact to know precisely where the real point of impact is

Thank you in advance for any help you can give me.


1 Like

This is a very odd sounding suspicion, but I wonder if you aren’t updating the RayCast2D in sync with your collision drawing script? RayCast2D collisions will get recalculated before _physics_process(delta) is called, so it would only be appropriate to draw your collision here, unless you manually update the ray via RayCast2D.force_raycast_update() before drawing.

Edit: In other words, this is to say I expect it might actually be working as expected, but your drawing is out of sync with physics updates.

1 Like

The red line is drawn by Godot, by checking debug visual colision shape, and the rotation of the arm (therefore of the raycast) is managed by _physics_process()


My goal is to make a shot, so I spawn a bullet with trail and move it toward the hit point. Then I active RigidBody of the bullet and let it fall on the floor.
That’s how I noticed the bug… The ball stopped before the wall. So it’s also physical. My debug point on the ray is placed like this:

func _physic_process(delta):
     raycast.get_child(0).global_position = raycast.get_collision_point()

I tried to turn arm after too, but same result…

My player object is like this, if that helps :slight_smile:


I also spawn a purple debug point after shot… Like this.

Here is my Tile Set too.

Because your RayCast2D is a child of PlayerArm, when you move the arm, you also move the raycast, potentially messing up the result unless you force an additional update. Does it work if you update the code to:

func _physic_process(delta):
     raycast.get_child(0).global_position = raycast.get_collision_point()

Edit: To avoid forcing additional updates, you can ensure you use the raycast results before changing its position/rotation.

Also, if you can’t get it working, you’re welcome to share the files and I’ll take a look :slight_smile:

1 Like

I try it, but that’s not the point.

So I send to @calebmhartshorn my project in mp and he find this line:

raycast.target_position *= 1e6

And said to me:
Apparently, 1,000,000 pixels is WAY too big, causing Godot’s physics engine to lose precision.
Setting it somewhere in the range of 2000 pixels seems to do the trick. You might consider setting it to some multiple of the screen size instead.

So, thank you much @calebmhartshorn, and remember people: Raycast don’t like to be too big… Sometimes the size matter !

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.