Quantcast
Channel: Questions in topic: "wheelcollider"
Viewing all articles
Browse latest Browse all 490

Wheel colliders facing the wrong direction

$
0
0
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: ![alt text][1] [1]: /storage/temp/159998-capture.png

Viewing all articles
Browse latest Browse all 490

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>