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

WheelCollider rotates mesh wrong

$
0
0
Hello, I want to work on a racing game, currently i only started creating the very Basics and i already stumbled upon a annoying bug. I have a WheelCollider and a mesh as a child on the Collider. I use GetWorldPose() from the wheelcollider to apply the wheelcollider Rotation to the child mesh. When i start the game, the z-axis always rotates 90°. I have no clue how to fix this :( Any help is highly appreciated :) [1]: /storage/temp/92907-play.png My script: `using System.Collections; using System.Collections.Generic; using UnityEngine; public class SimpleCarController : MonoBehaviour { public List axleInfos; public float maxMotorTorque; public float maxSteeringAngle; public void ApplyLocalPositionToVisuals(WheelCollider collider) { if (collider.transform.childCount == 0) { return; } Transform visualWheel = collider.transform.GetChild(0); Vector3 position; Quaternion rotation; collider.GetWorldPose(out position, out rotation); visualWheel.transform.position = position; visualWheel.transform.rotation = rotation; } public void FixedUpdate() { float motor = maxMotorTorque * Input.GetAxis("Vertical"); float steering = maxSteeringAngle * Input.GetAxis("Horizontal"); foreach (AxleInfo axleInfo in axleInfos) { if (axleInfo.steering) { axleInfo.leftWheel.steerAngle = steering; axleInfo.rightWheel.steerAngle = steering; } if (axleInfo.motor) { axleInfo.leftWheel.motorTorque = motor; axleInfo.rightWheel.motorTorque = motor; } ApplyLocalPositionToVisuals(axleInfo.leftWheel); ApplyLocalPositionToVisuals(axleInfo.rightWheel); } } } [System.Serializable] public class AxleInfo { public WheelCollider leftWheel; public WheelCollider rightWheel; public bool motor; // is wheel attached to motor public bool steering; // does wheel apply steering force } `

Viewing all articles
Browse latest Browse all 490

Trending Articles



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