Hinge Joint 2D motor ?

Hi guys,
I’m working on a 2d game. I connected a dirt bike to its wheels by a hinge joint, but i can’t change the motor speed of the hinge joint motor.
Can you help me?
Tips are welcome!:smile:

Thank you :slight_smile:

You have to manually assign a motor object to the hinge motor.

using UnityEngine;
using System.Collections;

public class HingeMotor : MonoBehaviour {

	// Use this for initialization
	void Start () {
		HingeJoint2D hinge = GetComponent<HingeJoint2D>();
		JointMotor2D motor = hinge.motor;
		motor.motorSpeed = 100f;
		hinge.motor = motor;
	}
	
	// Update is called once per frame
	void Update () {
	
	}
}
1 Like

Thank you for your help.:slight_smile: Your code works great!