#rotation problem

1 messages · Page 1 of 1 (latest)

lament garnet
#

for some reason two lines in my code dont let my wheel rotate

#

Here is my initial code and how it works

#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

  public class wheelmovement : MonoBehaviour
{
    
 
public void Update()
 {
    GetInput(); 

 }
public void GetInput()
{
m_horizontalInput = Input.GetAxis("Horizontal");
m_verticalInput = Input.GetAxis("Vertical");

}
private void Steer()
{
m_steeringAngle = maxSteerAngle * m_horizontalInput;

Steering.transform.eulerAngles = new Vector3(Steering.transform.eulerAngles.x, m_steeringAngle, Steering.transform.eulerAngles.z );
}


private void accelerate()
{
rearDriverW.motorTorque = m_verticalInput * motorForce;

}
private void UpdateWheelPoses()
{
UpdateWheelPose(frontDriverW, frontDriverT);

UpdateWheelPose(rearDriverW, rearDriverT);

}



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 frontDriverW;
public WheelCollider rearDriverW;
public Transform frontDriverT;
public Transform rearDriverT;
public float maxSteerAngle = 30;
public float motorForce = 50;
public Transform Steering;

}

#
private void UpdateWheelPoses()
{
UpdateWheelPose(frontDriverW, frontDriverT);

UpdateWheelPose(rearDriverW, rearDriverT);

}

#

but if i remove this code

#

then wheels dont rotate but they turn