- Home /
Clamp Bike Rotation
Hello! This is about my second week of using Unity, but I've started a game for my friend. My dirt bike model is falling because it is rotating so much. (this happens only when you go on a ramp, it is a long fall and you rotate alot). Here is my steering code:
var frontWheel1: WheelCollider;
var frontWheel2: WheelCollider;
var backWheel1: WheelCollider;
var backWheel2: WheelCollider;
var backWheel: Transform;
var frontWheel: Transform;
var power: int;
var steerPower: float;
var sharpPower: float;
//var steerEquiv: float;
var brakePower: float;
var newCenter: Vector3;
function Update () {
backWheel1.motorTorque = backWheel2.motorTorque = (-Mathf.Clamp(Input.GetAxis("Vertical"),-1,1)*power);
backWheel1.brakeTorque = backWheel2.brakeTorque = (Input.GetAxis("Vertical") == 0 ? brakePower : 0);
//backWheel.Rotate(0,(backWheel1.steerAngle+backWheel2.steerAngle)/(2*steerEquiv),0);
//frontWheel.Rotate(0,(frontWheel1.steerAngle+frontWheel2.steerAngle)/(2*steerEquiv),0);
frontWheel1.steerAngle = frontWheel2.steerAngle = (Input.GetButton("Sharp Turn")) ? sharpPower : steerPower * Input.GetAxis("Horizontal");
}
function Start(){
rigidbody.centerOfMass = newCenter;
}
How would I clamp its Z rotation?
maybe this is not the same but here you can find the way: http://answers.unity3d.com/questions/33753/car-tire-rotating-to-the-incorrect-direction/33765#33765
Sorry but its not... The wheels are going in the right direction, it's just that the whole bike rotates too much
Your answer
Follow this Question
Related Questions
can anyone help me stop a rigidbody from rotating around its z axis 1 Answer
Rotating a Rigidbody with Physics 1 Answer
How may I observe expected physical interactions while using Rigidbody.MoveRotation()? 1 Answer
Anti-Gravity vehicle bounce-back help. 1 Answer
Need help with limiting rotation. 1 Answer