Problem with wheeljoint2d motor: nothing happens when changing speed

For some reason I’m unable to adjust the “motor” value of a wheeljoint2D.

public JointMotor2D motor;

//...
void Start() {
this.motor = this.gameObject.GetComponent<WheelJoint2D>().motor;
}

    void Update() {
        this.motor.motorSpeed = -1000f;   
       Debug.Log(this.motor.motorSpeed); // this will print "-1000f" but nothing happens
     
    }

The above code prints “-1000f” just fine, but in the inspector the motor speed remains 0.

If I adjust the motor speed in inspector, the wheel starts rotating just fine.

Any idea what could be wrong? (Using unit y4.6.1f1)

Okay, I got it sorted out. What a strange thing :slight_smile: After “getting motor” I must adjust values and “set motor back to wheeljoint”.

So, here’s examples:

// this is the basic setup... 
    public WheelJoint2D wheeljointFront;
    public JointMotor2D motorFront;

this one does NOT work:

//this doesn't work
        this.motorFront = this.wheeljointFront.motor;
        this.motorFront.motorSpeed = -1000f;

here the thing that works:

        this.motorFront = this.wheeljointFront.motor;
        this.motorFront.motorSpeed = -1000f;   
        this.wheeljointFront.motor = this.motorFront;