- Home /
PhysicalMaterial is not changing through my code. [solved]
void Start()
{
NoSlip = new PhysicMaterial
{
//name = "walll",
staticFriction = 1f,
dynamicFriction = 1f,
frictionCombine = PhysicMaterialCombine.Maximum
};
Slip = new PhysicMaterial
{
staticFriction = 0f,
dynamicFriction = 0f,
frictionCombine = PhysicMaterialCombine.Minimum
};}
private void OnCollisionstay(Collision collision)
{
CapsuleCol.material = NoSlip;
}
private void OnCollisionExit(Collision collision)
{
CapsuleCol.material = Slip;
} public void TriggerJump()//this worked for changing the Ph.material
{
CapsuleCol.material = NoSlip;
float counter = 0
counter += 1f
if(counter == 2)
{
CapsuleCol.material = Slip;
}
}
When Iam entering playmode I see that my charactercollider got a physical material attached to it but that material is not changing anymore with this code. The physical material only changed when I used a if statement in the same void function see code. What I also find out was if I changed the order of declaration in start that it would do the opposite, so the default NoSlip would change to Slip in playmode after that it wouldn't change. Things I have already tried: 1.deleting my own made p.material 2. putting code in fixedupdate 3. using other variable to hold the p.material (newslip = NoSlip;) 4. Deleting or adding p.materials to objects in scene. 5. Checking with Debug.log if OnCollisionStay works. I hope that I have given enough information, thanks in advance.
Check your colliders will send messages. Take a look at the collision matrix at the bottom of this page - https://docs.unity3d.com/$$anonymous$$anual/CollidersOverview.html
Yes my collider is sending messages, both the stay en exit collider. But my P.material is still not changing... @Warmedx$$anonymous$$ints
Answer by mike29willems · Mar 17, 2019 at 11:20 PM
Collision were working, I tagged all walkable game object the same. The problem with that is even if u have a cube were u can walk on, the sides of that cube behave as a wall. So by tagging a walkable object like a cube, ur tagging the 'notwalkable' wall as well . Because I used OnCollisionexit to see if grounded, the moment I jump off the ground he detects the wall and think I'am grounded causing the rest of my code not to work well. Thanks for the help