Hello all,
I am working on my first Unity project mostly for the purposes of getting better at C# first.
I have created my own little physics engine and I want to replicate the Physics Material functionality of RidgidBody but I am not sure of how exactly the best way to achieve this is.
The built-in Physics Materials currently do not accommodate the type of data for my engine I need.
What I have:
MyPhysicsBody.csMyPhysicsMaterial.cs
MyPhysicsBody.cs is akin to RigidBody and requires a public MyPhysicsMaterial to work.
My question now is mostly how to supply this material because my initial hunch has one snag.
MyPhysicsMaterial.cs
public class MyPhysicsMaterial
{
public string x;
public float y;
public float z;
public MyPhysicsMaterial(string x, float y, float z)
{
this.x = x;
this.y = y;
this.z = z;
}
}
So this approach seems to make the most sense to me as the developer could then dynamically create a material. However, I am not sure how I can provide a set of in-built materials.
What I believe is the correct answer may be to create a class for each material and have it inherit the MyPhysicsMaterial class, but this seems cumbersome and would lack auto-completion.
I think I would like to have something like this available:
MyPhysicsBody.material = MyPhysicsMaterial.Wood()
So I added that as a method:
public MyPhysicsMaterial Aluminum()
{
return new MyPhysicsMaterial("Aluminum", y, z);
}
That would probably work fine and I do think is maybe my preferred method but this means that the developer wouldn’t be able to choose the material from the inspector as far as I can tell?
Edit:
I actually just discovered you can not actually have a class field in the inspector, meaning having a class for each material won’t work either. So at the moment, I can find no way to implement a system similar to physics materials where I could have a small library of “materials” for the dev to swap in.
It may be worth noting that at the moment, a “material” in my engine at the current moment is only 3 variables that.
Any help is majorly appreciated. Thank you.