- Home /
Question by
tulloch100 · Aug 11, 2017 at 01:06 PM ·
speedaccelerationcar physics
Why are my wheels not moving at the same speed as my car?
Hi Everyone hope your having a good day so far
Iv been trying to figure this problem out for a week now with no luck. I need a little bit of help with some wheel rotation I set up for my game. I can't seem to work out why my wheels are moving 3x faster than acceleration speed of my car. I also cant work out why my car is moving so slow and the brakes take ages to slow down.
Have I set something in the inspector too high cause I'm thinking it might have something to do with my wheel script that i have setup with the car.
Here is a video of the problem i'm having.
using System.Collections;
using UnityEngine;
public class Car : MonoBehaviour
{
public float maxTorque = 5000f;
public float speed = 5000f;
public Transform centerofMass;
public WheelCollider[] wheelColliders = new WheelCollider[4];
public Transform[] tireMeshes = new Transform[4];
private Rigidbody m_rigidBody;
void Start()
{
m_rigidBody = GetComponent<Rigidbody>();
m_rigidBody.centerOfMass = centerofMass.localPosition;
}
void Update()
{
UpdateMeshesPositions();
}
void FixedUpdate()
{
float steer = Input.GetAxis ("Horizontal");
float accelrate = Input.GetAxis ("Vertical");
float finalAngle = steer * 45f;
wheelColliders [0].steerAngle = finalAngle;
wheelColliders [1].steerAngle = finalAngle;
for (int i = 0; i < 4; i++)
{
wheelColliders[i].motorTorque = accelrate * speed * maxTorque; }
}
void UpdateMeshesPositions()
{
for(int i = 0; i < 4; i++)
{
Quaternion quat;
Vector3 pos;
wheelColliders[i].GetWorldPose(out pos, out quat);
tireMeshes[i].position = pos;
tireMeshes[i].rotation = quat;
}
}
}
Comment