Skip to content

Instantly share code, notes, and snippets.

@augustoerico
Created December 28, 2017 22:18
Show Gist options
  • Save augustoerico/13ab33914726953df20d6b9fe4efc148 to your computer and use it in GitHub Desktop.
Save augustoerico/13ab33914726953df20d6b9fe4efc148 to your computer and use it in GitHub Desktop.
using UnityEngine;
public class CarMovement : MonoBehaviour {
public WheelCollider rl = null;
public WheelCollider rr = null;
public WheelCollider fl = null;
public WheelCollider fr = null;
public float torque = 10.0f;
public float brakeStrength = 5.0f;
public float steering = 10.0f;
void Update () {
float acceleration = Input.GetAxis ("Vertical") * torque;
float steer = Input.GetAxis ("Horizontal");
Debug.Log (acceleration);
rl.motorTorque = acceleration;
rr.motorTorque = acceleration;
fl.steerAngle = steer * steering;
fr.steerAngle = steer * steering;
/*if (acceleration > 0.0f) {
rl.motorTorque = acceleration * torque;
rr.motorTorque = acceleration * torque;
} else if (acceleration < 0.0f) {
rl.brakeTorque = brakeStrength;
rr.brakeTorque = brakeStrength;
} else {
rl.brakeTorque = 0;
rr.brakeTorque = 0;
}*/
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment