Hi! I just made a script from tutorial and now wheels are spinning wrong axis. Please help.
Here is code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SimpleCarController : MonoBehaviour
{
public void GetInput()
{
m_horizontalInput = Input.GetAxis("Horizontal");
m_verticalInput = Input.GetAxis("Vertical");
}
private void Steer()
{
m_steeringAngle = maxSteerAngle * m_horizontalInput;
frontW.steerAngle = m_steeringAngle;
}
private void Accelerate()
{
rearW.motorTorque = m_verticalInput * motorForce;
}
private void UpdateWheelPoses()
{
UpdateWheelPose(frontW, frontT);
UpdateWheelPose(rearW, rearT);
}
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 m_horizontalInput;
private float m_verticalInput;
private float m_steeringAngle;
public WheelCollider frontW;
public WheelCollider rearW;
public Transform frontT;
public Transform rearT;
public float maxSteerAngle = 30;
public float motorForce = 50;
}
Here is video:
kovpqi

