- Home /
Question by
miman888 · May 21, 2020 at 10:05 AM ·
blendercarwheelcollider
Wheel colliders facing the wrong direction
Hi, i imported my own custom car model from blender and applied wheelcolliders to all of the wheels. But unfortunately my wheels are turning on the wrong axis. I do not know how to fix the way the wheelcolliders are facing.
Here is my code from my car script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CarController : MonoBehaviour
{
public void GetInput()
{
horizontalInput = Input.GetAxis("Horizontal");
verticalInput = Input.GetAxis("Vertical");
}
private void Steer()
{
steerAngle = maxSteerAngle * horizontalInput;
frontLeftW.steerAngle = steerAngle;
frontRightW.steerAngle = steerAngle;
}
private void Accelerate()
{
frontLeftW.motorTorque = motorForce * verticalInput;
frontRightW.motorTorque = motorForce * verticalInput;
}
private void UpdateWheelPoses()
{
UpdateWheelPose(frontLeftW, frontLeftT);
UpdateWheelPose(frontRightW, frontRightT);
UpdateWheelPose(rearLeftW, rearLeftT);
UpdateWheelPose(rearRightW, rearRightT);
}
private void UpdateWheelPose(WheelCollider collider, Transform transform)
{
Vector3 pos = transform.position;
Quaternion quat = transform.rotation;
collider.GetWorldPose(out pos, out quat);
transform.position = pos;
transform.rotation = quat;
}
private void FixedUpdate()
{
GetInput();
Steer();
Accelerate();
UpdateWheelPoses();
}
private float horizontalInput;
private float verticalInput;
private float steerAngle;
public WheelCollider frontLeftW, frontRightW;
public WheelCollider rearLeftW, rearRightW;
public Transform frontLeftT, frontRightT;
public Transform rearLeftT, rearRightT;
public float maxSteerAngle = 30;
public float motorForce = 50;
}
And here is a picture of what is happening to my wheel:
capture.png
(17.8 kB)
Comment