Obi Official Forum
Collision filtering for ropes - 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: Collision filtering for ropes (/thread-3127.html)



Collision filtering for ropes - linkinb - 10-10-2021

Hi, I am not able to undestand the documentation of collision filtering.

I'm trying to disable collision filtering between a rope and a particular collider on attachment (to avoid jitter)
Now I can do this via the editor by changing the "Collides with" property on my obi collider to exclude 0, that way it doesn't collided with anything that's in category 0.
How can i do this via code?

I see that in examples I can access a filter property, and that is being changed by int filter = ObiUtils.MakeFilter(ObiUtils.CollideWithEverything, 0), But i can't find any documentation or tooltips on how to use this to set up collision filtering via script. 
Please help. 

thanks


RE: Collision filtering for ropes - josemendez - 10-10-2021

(10-10-2021, 07:24 AM)linkinb Wrote: I see that in examples I can access a filter property, and that is being changed by int filter = ObiUtils.MakeFilter(ObiUtils.CollideWithEverything, 0), But i can't find any documentation or tooltips on how to use this to set up collision filtering via script. 

Like most things in Obi, filters are a per-particle property. The scripting section of the manual explains how to get/set per particle properties, and the filter is listed among them:

http://obi.virtualmethodstudio.com/manual/6.2/scriptingparticles.html

For example, to set the filter for all particles in a rope you'd do:

Code:
var myFilter = ObiUtils.MakeFilter(ObiUtils.CollideWithEverything, 0);
for (int i = 0; i < rope.solverIndices.Length; ++i)
     rope.solver.filters[rope.solverIndices[i]].filter = myFilter;



RE: Collision filtering for ropes - linkinb - 10-10-2021

(10-10-2021, 11:06 AM)josemendez Wrote: Like most things in Obi, filters are a per-particle property. The scripting section of the manual explains how to get/set per particle properties, and the filter is listed among them:

http://obi.virtualmethodstudio.com/manual/6.2/scriptingparticles.html

For example, to set the filter for all particles in a rope you'd do:

Code:
var myFilter = ObiUtils.MakeFilter(ObiUtils.CollideWithEverything, 0);
for (int i = 0; i < rope.solverIndices.Length; ++i)
     rope.solver.filters[rope.solverIndices[i]].filter = myFilter;


what if I want my rope to collide with 1 type of collider, but not another type of collider, how would I set that up?
for example say i have a sphere and a cube. I want my rope to collide with the sphere but not with the cube, how would that set up look like via code? 

Like how can i change the "Collides with" property that you see in the inspector on all obi colliders?


RE: Collision filtering for ropes - josemendez - 11-10-2021

(10-10-2021, 12:12 PM)linkinb Wrote: what if I want my rope to collide with 1 type of collider, but not another type of collider, how would I set that up?
for example say i have a sphere and a cube. I want my rope to collide with the sphere but not with the cube, how would that set up look like via code? 

Your rope:
Code:
var myFilter = ObiUtils.MakeFilter(1 << 1, 0);
for (int i = 0; i < rope.solverIndices.Length; ++i)
     rope.solver.filters[rope.solverIndices[i]].filter = myFilter;

The sphere:
Code:
sphereObiCollider.Filter = ObiUtils.MakeFilter(ObiUtils.CollideWithEverything, 1);

The cube:
Code:
cubeObiCollider.Filter = ObiUtils.MakeFilter(ObiUtils.CollideWithEverything, 0);

That's one possibility: giving the rope a mask that only collides with category 1, placing the sphere in category 1 and the cube in category 0. You could do it in many other ways.

(10-10-2021, 12:12 PM)linkinb Wrote: Like how can i change the "Collides with" property that you see in the inspector on all obi colliders?

Filters are made of a mask and a category. The mask (the "Collides with" field) is the first parameter of the ObiUtils.MakeFilter() function. Just keep in mind the mask is a bit mask (just like Unity's layer masks), so you build it by simply or'ing together bits. For instance, to build a mask that collides with categories 1, 3, and 6:

Code:
int mask = (1 << 1) | (1 << 3) | (1 << 6);
ObiUtils.MakeFilter(mask, 0); // used category 0, could use any other.

Note you need to be familiar with bitwise operators to understand this. If you're not sure what this means, look them up. There's many tutorials around dealing with bit manipulation (in C# as well as other languages), the above link to Unity's layer masks is a good starting point as they work just like Obi's filter masks.


RE: Collision filtering for ropes - linkinb - 11-10-2021

(11-10-2021, 08:57 AM)josemendez Wrote: Your rope:
Code:
var myFilter = ObiUtils.MakeFilter(1 << 1, 0);
for (int i = 0; i < rope.solverIndices.Length; ++i)
     rope.solver.filters[rope.solverIndices[i]].filter = myFilter;

The sphere:
Code:
sphereObiCollider.Filter = ObiUtils.MakeFilter(ObiUtils.CollideWithEverything, 1);

The cube:
Code:
cubeObiCollider.Filter = ObiUtils.MakeFilter(ObiUtils.CollideWithEverything, 0);

That's one possibility: giving the rope a mask that only collides with category 1, placing the sphere in category 1 and the cube in category 0. You could do it in many other ways.


Filters are made of a mask and a category. The mask (the "Collides with" field) is the first parameter of the ObiUtils.MakeFilter() function. Just keep in mind the mask is a bit mask (just like Unity's layer masks), so you build it by simply or'ing together bits. For instance, to build a mask that collides with categories 1, 3, and 6:

Code:
int mask = (1 << 1) | (1 << 3) | (1 << 6);
ObiUtils.MakeFilter(mask, 0); // used category 0, could use any other.

Note you need to be familiar with bitwise operators to understand this. If you're not sure what this means, look them up. There's many tutorials around dealing with bit manipulation (in C# as well as other languages), the above link to Unity's layer masks is a good starting point as they work just like Obi's filter masks.


Thanks this was very helpful!