public void ControlCar() { float motor = currentGear.MaxMotorTorque * acel; float steering = currentGear.MaxSteeringAngle * steer; //speedText.text = "Speed: " + rb.velocity.magnitude.ToString(); if (rb.velocity.magnitude > currentGear.MinimumSpeed) { motor *= 2.0f; } else { motor *= 0.25f; } if (Input.GetKey(KeyCode.Space)) { //if braking you cannot stear?! Brake(); return; } for (int i = 0; i < AxleInfoVRs.Length; i++) { AxleInfoVR axle = AxleInfoVRs[i]; //Adjust steering if (axle.Steering) { axle.LeftWheel.steerAngle = steering; axle.RightWheel.steerAngle = steering; } //Adjust motor power if (axle.Motor) { axle.LeftWheel.motorTorque = motor; axle.RightWheel.motorTorque = motor; axle.LeftWheel.brakeTorque = 0.0f; axle.RightWheel.brakeTorque = 0.0f; } ApplyLocalPositionsToVisuals(axle.LeftWheel); ApplyLocalPositionsToVisuals(axle.RightWheel); } }
//[SerializeField] //private Text speedText; //[SerializeField] //private Text gearText; // Start is called before the first frame update void Start() { rb = this.GetComponent <Rigidbody>(); visualWheelOffset = AxleInfoVRs[0].LeftWheel.transform.GetChild(0).eulerAngles; currentGear = gears[0]; //speedText.text = "Speed: 0"; //gearText.text = "Gear: 1"; for (int i = 0; i < AxleInfoVRs.Length; i++) { AxleInfoVR axle = AxleInfoVRs[i]; axle.RightWheel.ConfigureVehicleSubsteps(20, 12, 16); axle.LeftWheel.ConfigureVehicleSubsteps(20, 12, 16); } }
private void Brake() { for (int i = 0; i < AxleInfoVRs.Length; i++) { AxleInfoVR axle = AxleInfoVRs[i]; if (axle.Motor) { axle.LeftWheel.motorTorque = 0.0f; axle.RightWheel.motorTorque = 0.0f; axle.LeftWheel.brakeTorque = brakespeed; axle.RightWheel.brakeTorque = brakespeed; } ApplyLocalPositionsToVisuals(axle.LeftWheel); //Don't think this should be here! ApplyLocalPositionsToVisuals(axle.RightWheel); } }