Hello everyone,
I’m working on Unity 2d project. and using hinge joint 2d to make animation for character.
Here is my code to make animation called “kick”.
public void Jump()
{
//Debug.Log (“Jump”);
if (grounded)
thisRigidbody.AddForce (jumpHeight * m_ThisTransform.up);
//hingeJoint2D.useMotor = false;
//hingeJoint2D = rightLeg.GetComponent ();
JointMotor2D motor = hingeJoint2D.motor;
if (team == Team.Left)
motor.motorSpeed = -motorSpeed;
else
motor.motorSpeed = motorSpeed;
hingeJoint2D.useMotor = true;
hingeJoint2D.motor = motor;
if (grounded)
grounded = false;
Invoke (“ResetLeg”, 0.2f);
}
void ResetLeg()
{
//hingeJoint2D = rightLeg.GetComponent ();
JointMotor2D motor = hingeJoint2D.motor;
if (team == Team.Left)
motor.motorSpeed = motorSpeed;
else
motor.motorSpeed = -motorSpeed;
hingeJoint2D.motor = motor;
//Invoke (“TurnOffMotor”, 0.1f);
}
Method working fine on first using. But when call “Jump” second, motor speed of JointMotor2D doest change.
Please suggest me some solution to fix this issue.
Thanks