Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Raycasting rope behind an object
#1
I have a rope hanging behind some objects. Objects are between the camera and the rope. 
The objects have an ObiCollider with category 0. 
The rope has category 1. 

I make a raycast from the camera towards the rope. I need the result to be returned only if it is not behind the object. 
So I am creating filter as 
int filter = ObiUtils.MakeFilter(ObiUtils.CollideWithEverything, 1);
var ray = _camera.ScreenPointToRay(Input.mousePosition);
solver.Raycast(ray, out QueryResult result, filter, 100f, 0.1f));

And unfortunately, every time I hit the rope, the result returns me the simplex of that rope. Even if she is behind an obstacle with ObiCollider. Is there a way for an obstacle to stop the raycast?
Reply
#2
Hi,

Obi and Unity's built-in physics are completely separate engines. This means raycasting in Obi only considers Obi particles and will ignore colliders (since they're not simulated by Obi, but by Unity's own physics engine).

The solution to your problem is to perform two raycasts: a regular Unity raycast to determine whether it hits a collider along the way, and it case it doesn't hit anything, a Obi raycast to determine which particle it hits (if any).

This is also more performant that a single raycast considering both colliders and particles would be, since it allows you to skip particles in case you hit a collider first.

kind regards
Reply
#3
(05-03-2024, 10:15 AM)josemendez Wrote: Hi,

Obi and Unity's built-in physics are completely separate engines. This means raycasting in Obi only considers Obi particles and will ignore colliders (since they're not simulated by Obi, but by Unity's own physics engine).

The solution to your problem is to perform two raycasts: a regular Unity raycast to determine whether it hits a collider along the way, and it case it doesn't hit anything, a Obi raycast to determine which particle it hits (if any).

This is also more performant that a single raycast considering both colliders and particles would be, since it allows you to skip particles in case you hit a collider first.

kind regards

Thanx!

I'll do it this way
Reply