Discrepancy between ECS Physics and PhysX Raycast hit position

Hello! I’m noticing there’s a discrepancy between the raycast hit point on a regular PhysX raycast and the ECS Raycast the farther away I am from origin. I’m not sure if this has to do with floating point precision, but there’s a noticeable difference around at least 50 units away from the origin. Also the offset error always has a bias towards the origin that’s stronger the farther away you get.

  • black dot is ray origin
  • blue dot PhysX hit position
  • red dot ECS Physics hit position
  • Blue dot is ~350 units away from origin and the accurate hit position.

All scaling is uniform and the rays are executed with the same references to ray origin and direction. I’ve tried different types of meshes to raycast against and got the same results.

Does the ECS Physics world just have less precision when it comes to Raycasts / floating point stuff? Am I missing something?

Unity Physics uses a Start position and an End position. Make sure you’re passing two positions, not a starting point and a direction.

Queries on matching collision bodies should have very similar results at this scale. Sharing a sample project showing this behavior would be useful if you want diagnosis.

Unity Physics uses a Start position and an End position. Make sure you’re passing two positions, not a starting point and a direction.

I’m assuming you can use a direction in this case by just putting direction * rayLength for the end position?

Queries on matching collision bodies should have very similar results at this scale. Sharing a sample project showing this behavior would be useful if you want diagnosis.

Thanks I’ll try a fresh project next and share it if this is unexpected.

It needs to be a world space position.

start position + direction x length

Wow! Very blind on my part but that explains everything and fixes the problem. Thanks for the help @Spy-Master!