Setting Wheel Collider Friction in C#

Hello guys, i have a problem with setting wheelcollider extremum slip in C#.

I will give a simple example.

public WheelCollider _colliderRR;

i have defined my collider and now i want to change its extremumSlip when i press “Space” key.

if(Input.GetKey(KeyCode.Space))
{
_colliderRR.sidewaysFriction.extremumSlip = 0.1f;
}

When i do this i have get the error saying:
“Cannot modify a value type return value of `UnityEngine.WheelCollider.sidewaysFriction’. Consider storing the value in a temporary variable”.

But i can change it in javascript with this way but it does not work in C#. Can you please show me how i can do it in C#.

Best regards.

Is there anyone can help me?

The sidewaysFriction is not expection a “float” but a “WheelFrictionCurve”
Get the WheelFrictionCurve from sidewaysFriction and modify it , then write it back to the sidewaysFriction.

1 Like

Thanks for your answer but i have already known what you said. However i do not know how i can do it. Can you give an example?

WheelFrictionCurve sideWaysFriction;

I mean after i have declared sideWaysFriction how can i connect it to my collider?
I have declared a collider as _colliderRR and i need to chang its extremum slip so can you tell me how i can access it via sideWaysFriction?

if(Input.GetKey(KeyCode.Space))
{
    WheelFrictionCurve myWfc;
    myWfc = _colliderRR.sidewaysFriction;
    myWfc.extremumSlip = 0.1f;
    _colliderRR.sidewaysFriction = myWfc;
}
4 Likes