- Home /
Question by
tulloch100 · Aug 07, 2017 at 10:37 PM ·
movementspeedcaracceleration
Wheel rotation help cant work out the problem?
Hi Everyone hope your having a good day so far
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
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
alt text
using System.Collections;
using UnityEngine;
public class Car : MonoBehaviour
{
public float maxTorque = 500f;
public float speed = 500f;
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
Your answer
Follow this Question
Related Questions
Why are my wheels not moving at the same speed as my car? 0 Answers
Rigidbody regenerated acceleration movement ? 0 Answers
Accelerate slowdown Player movement 0 Answers
How to reach a specific max speed with AddForce() ? 1 Answer
Acceleration with CC 0 Answers