Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Obi Fluid Materials Question
#1
Hello,

Sorry if this question has been asked elsewhere, I tried looking but found nothing. Basically, do collision materials override? What I mean is, let's say I set my emitter to have a specific material (ie, ice), but another object with a collider to a different material (ie, high friction). Will the fluid react to every other collider as 'ice,' but react to the specified object as 'high friction'? Or will it choose the emitter material instead?

The reason I ask is that I have a character whose colliders are created with a script in-game, so I have another script to add the ObiCollider component after that to get around the ObiCollider requirement. When I try to add a material to the recently created colliders, it says that the material property is inaccessible (I assume its a private variable and I don't just want to start messing with the code at will). I would like to set the materials for this character's colliders to be different than other objects in the game, and I don't really know the best way to go about this.

Thanks in advance! Guiño
Reply
#2
(18-02-2022, 12:14 AM)Freebird17 Wrote: Hello,

Sorry if this question has been asked elsewhere, I tried looking but found nothing. Basically, do collision materials override? What I mean is, let's say I set my emitter to have a specific material (ie, ice), but another object with a collider to a different material (ie, high friction). Will the fluid react to every other collider as 'ice,' but react to the specified object as 'high friction'? Or will it choose the emitter material instead?

Collision materials behave exactly like physics materials in Unity (and pretty much all physics engines): when two objects with different collision materials collide, the collision values used for friction, adhesion, etc are calculated according to the "combine" settings of the materials.

See:
http://obi.virtualmethodstudio.com/manua...rials.html
https://docs.unity3d.com/Manual/class-Ph...erial.html

For instance, in a collision involving a material with zero friction and a material with 0.8 friction that have "friction combine" set to average, the resulting friction is (0 + 0.8)/2 = 0.4. If the materials have different combine settings, they're used in order of preference (lowest enum index first).

(18-02-2022, 12:14 AM)Freebird17 Wrote: The reason I ask is that I have a character whose colliders are created with a script in-game, so I have another script to add the ObiCollider component after that to get around the ObiCollider requirement. When I try to add a material to the recently created colliders, it says that the material property is inaccessible (I assume its a private variable and I don't just want to start messing with the code at will). I would like to set the materials for this character's colliders to be different than other objects in the game, and I don't really know the best way to go about this.

Thanks in advance! Guiño

ObiCollider.CollisionMaterial is a public property, you might have been trying to access its private backing field. You should be able to set it in a script, see the API docs for details:
http://obi.virtualmethodstudio.com/api.html

cheers!
Reply
#3
(18-02-2022, 08:52 AM)josemendez Wrote: Collision materials behave exactly like physics materials in Unity (and pretty much all physics engines): when two objects with different collision materials collide, the collision values used for friction, adhesion, etc are calculated according to the "combine" settings of the materials.

See:
http://obi.virtualmethodstudio.com/manua...rials.html
https://docs.unity3d.com/Manual/class-Ph...erial.html

For instance, in a collision involving a material with zero friction and a material with 0.8 friction that have "friction combine" set to average, the resulting friction is (0 + 0.8)/2 = 0.4. If the materials have different combine settings, they're used in order of preference (lowest enum index first).


ObiCollider.CollisionMaterial is a public property, you might have been trying to access its private backing field. You should be able to set it in a script, see the API docs for details:
http://obi.virtualmethodstudio.com/api.html

cheers!
Thank you so much for the help! I was trying to reference the property as ObiCollider.material, not ObiCollider.CollisionMaterial. I have a follow-up question, though. I'm pretty new to unity and C#, and I can't seem to figure out how to assign the CollisionMaterial asset reference. Right now, I have
Code:
var Object = AssetDatabase.LoadMainAssetAtPath ("Assets/Obi/Samples/Common/SampleResources/CollisionMaterials/MyFriction.asset");
And then
Code:
GameObject.Find("shoulder.R").AddComponent<ObiCollider>();
GameObject.Find("shoulder.R").GetComponent<ObiCollider>().CollisionMaterial = Object;
And I keep getting an error that 'Object is a type, which is not valid in the given context'. How would I properly assign the 'MyFriction' asset to the collider material via a script?
Reply
#4
Turns out I solved this, I just didn't understand how to add asset references to components via a script. For anyone wondering, I basically followed this tutorial exactly:
https://www.youtube.com/watch?v=7GcEW6uwO8E

And then added this bit of code to my script:
Code:
GameObject.Find("xxx").GetComponent<ObiCollider>().CollisionMaterial = (GameAssets.i.yyy);
Where 'xxx' is the desired object and 'yyy' is the material name in the GetAssets script.

Thanks again a ton josemendez for the help! Gran sonrisa
Reply