1
\$\begingroup\$

I need help with some wheel rotation I set up for my game. My wheels are moving 3x faster than the acceleration speed of my car. Also, I can't work out why my car is moving so slow and the brakes not working.

Have I set something in the inspector too high? I think that it might have something to do with my wheel script.

enter image description here enter image description here

Here is a video of my problem www.youtube.com/watch?v=0YI50cJ5X4Q&feature=youtu.be

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;
    }
}

}

\$\endgroup\$
  • \$\begingroup\$ Bump.........,. \$\endgroup\$ – Harold Tulloch Aug 12 '17 at 0:28
  • \$\begingroup\$ Comments alone aren't enough to bump a thread here. If you want the question to get more attention, you can edit it to add more information, or participate in other Q&A to earn enough reputation to add a bounty on your question as an incentive. Back to your question itself, it looks like you're applying too much torque to the tires for their friction settings and initial speed, so they end up slipping instead of gripping the road - like peeling out in a real car, burning the rubber instead accelerating smoothly. Have you tried using less torque or a more gradual acceleration from stop? \$\endgroup\$ – DMGregory Aug 12 '17 at 13:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.