- Home /
Question by
WholeFruitcake · Aug 26, 2015 at 12:29 PM ·
rotationrigidbody2djointsmotor
How do i get a reverse rotation happening on right click down
This is what i have so far, only rotates one way on left click down, need it to do the opposite in the same script can anyone give me a hand?
using UnityEngine; using System.Collections;
public class ArmRotation : MonoBehaviour {
public float force=20;
public float speed=10000;
private HingeJoint2D joint;
private JointMotor2D motor1;
void Start()
{
joint = GetComponent<HingeJoint2D>(); // Get hingejoint
motor1.motorSpeed = speed;
motor1.maxMotorTorque = force;
joint.motor = motor1;
joint.useMotor = false;
}
void Update ()
{
if(Input.GetMouseButtonDown(0))
{
joint.useMotor = true;
}
if(Input.GetMouseButtonUp(0))
{
joint.useMotor = false;
}
}
}
Comment
Answer by jimbobulus2 · Aug 28, 2015 at 06:12 PM
Have you tried setting the motor speed to minus speed?
if(Input.GetMouseButtonDown(0)) {
motor1.motorSpeed = speed;
}
if(Input.GetMouseButtonUp(0)) {
motor1.motorSpeed = -speed;
}
Your answer
Follow this Question
Related Questions
Rigidbody2D rotation spinning wildly when attaching by joint to another Rigidbody2D 0 Answers
How to acquire and use WheelJoint2D jointSpeed in my own formula 0 Answers
Joint does not rotate back to original position. 0 Answers
Best practice for avoiding bad collisions when rotating a Rigidbody2D player? 0 Answers