using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class move : MonoBehaviour
{
//vars
public WheelCollider[] w;
public Rigidbody rb;
public GameObject com;
public float speed = 100;
public float trun = 45;
public float maxspeed = 100f;
public float speedpower;
void Start()
{
//centerOfMass
rb.centerOfMass = com.transform.localPosition;
}
void FixedUpdate()
{
speedpower = Input.GetAxis("Vertical");
// for max and min speed
speedcon();
//movement
movement();
}
void movement()
{
//forward and back
foreach (var wheel in w)
{
wheel.motorTorque = speed * 5 / 4;
}
//truning
for (int i = 0; i < w.Length; i++)
{
if (i < w.Length)
{
w[i].steerAngle = Input.GetAxis("Horizontal") * trun;
}
}
}
void speedcon()
{
max();
min();
}
void max()
{
if (speed > maxspeed)
{
speed = maxspeed;
}
else
{
speed += speedpower;
}
}
void min()
{
if (speed < 0)
{
speed = 0f;
}
else
{
speed += speedpower;
}
}
}