Obi Official Forum
Help Raycasting rope behind an object - Printable Version

+- Obi Official Forum (https://obi.virtualmethodstudio.com/forum)
+-- Forum: Obi Users Category (https://obi.virtualmethodstudio.com/forum/forum-1.html)
+--- Forum: Obi Rope (https://obi.virtualmethodstudio.com/forum/forum-4.html)
+--- Thread: Help Raycasting rope behind an object (/thread-4123.html)



Raycasting rope behind an object - Apoll0 - 05-03-2024

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?


RE: Raycasting rope behind an object - josemendez - 05-03-2024

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


RE: Raycasting rope behind an object - Apoll0 - 05-03-2024

(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