How to modify the value of Wheeljoint2D-s frequency? It says it's not a variable.

Hello everyone!

I’m not very good at c# jet, I try to set the frequency and damping ratio on my obejct using a script with this:

 foreach (Component bone in bones)
        {
                WheelJoint2D temp3 = bone.gameObject.AddComponent(typeof(WheelJoint2D)) as WheelJoint2D;
                bone.gameObject.GetComponent<WheelJoint2D>().suspension.frequency = 1f;
        }

But it says: “Cannot modify the return value of ‘WheelJoint2D.suspension’ because it is not a variable”.
How am I suppose to modify it then? It doesn’t have a setter either, what is this c# blackmagic?

Wisy you all a lovely day!

        WheelJoint2D wd = GetComponent<WheelJoint2D>();
        JointSuspension2D js = wd.suspension;
        js.frequency = 34f;
        wd.suspension = js;

JoinSuspension2D is a strut, so similar to how you modify a Vector3, you need to do it in the way I’ve shown here.

2 Likes