2
\$\begingroup\$

I have a wheel joint 2D attached to a game object in Unity:

Wheel Components

In its associated wheel script I am increasing the motor speed as described in the tutorial.

public class Wheel : MonoBehaviour
{
    WheelJoint2D wheel;
    JointMotor2D motor;

    void Start()
    {
        wheel = GetComponent<WheelJoint2D>();
        motor = wheel.motor;
    }

    void Update()
    {
        if (Input.GetKey(KeyCode.RightArrow))
            motor.motorSpeed += 10;

        if (Input.GetKey(KeyCode.LeftArrow))
            motor.motorSpeed -= 10;

        //Debug.Log(motor.motorSpeed);
    }
}

The problem is that the sprite does not rotate and I am not certain as to why?

Does the wheel joint have to be attached to another rigid body in order to function?

\$\endgroup\$

1 Answer 1

2
\$\begingroup\$

You have to attach the wheeljoint2d to another sprite wich with a rigidbody2d for it to work. So yes, you should attach it to another rigidbody2d.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .