- Home /
Question by
alexander11 · Oct 13, 2014 at 05:36 AM ·
inputrigidbody2dphysics2d
2D car brakes help???
hello im having trouble with my brake system when i press space and S the car flys off and it only works forward but not backwards this is really made me mad and cant find the answer :|
heres the code
using UnityEngine;
using System.Collections;
public class NewBehaviourScript : MonoBehaviour {
public float speedF = 10f;
public float speedB = 10f;
public float mph;
public Vector2 hat;
public float throttle;
public float moderation = 0.5f;
public float decrease = 0.3f;
public bool braked = false;
public bool brakeS = false;
public GameObject wheelB;
public GameObject wheelF;
private Vector2 speed = new Vector2(3, 0);
void Start()
{
}
void OnGUI(){
mph = rigidbody2D.velocity.magnitude * 1;
Debug.Log("Mph: " + mph);
}
void FixedUpdate()
{
handBrake ();
}
void Update () {
throttle +=Input.GetAxis("Vertical")* 50;
throttle -= decrease;
throttle = Mathf.Clamp(throttle,0,25);
print (throttle);
if(Input.GetKey(KeyCode.W))
{
wheelB.rigidbody2D.AddTorque(throttle);
}
if(Input.GetKey(KeyCode.S))
{
wheelB.rigidbody2D.AddTorque(-speedB);
}
}
void handBrake()
{
if(Input.GetButton("Jump"))
{
braked = true;
}
else
{
braked = false;
}
if(braked)
{
//wheelB.transform.rotation = Quaternion.identity;
//wheelB.rigidbody2D.AddTorque(-mph * 10);
wheelB.rigidbody2D.AddTorque(-mph * 10);
}
}
}
Comment
Best Answer
Answer by alexander11 · Oct 14, 2014 at 05:59 PM
i fixed it with fixedangle
You might want to elaborate on how you did it for future visitors of this question.