Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question Who tf do pivot points with wheel coliders work?

Discussion in 'Editor & General Support' started by xxfelixlangerxx, Apr 11, 2020.

  1. xxfelixlangerxx

    xxfelixlangerxx

    Joined:
    Feb 6, 2019
    Posts:
    31
    Hi,
    i'm stuck at making wheels for my karting game.
    I am using wheel coliders however the pivot points and rotation just completly blew my mind. Have been trying for about 3 hours now however I still dont understand this.

    This is how it looks in the editior.
    When playing the wheels snap into the correct position however when turning I get this result:

    How do I fix this. Do I need a nother set of emptys?

    This is the only code I am using from the wheelcollider tutorial.

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4.  
    5. [System.Serializable]
    6. public class AxleInfo
    7. {
    8.     public WheelCollider leftWheel;
    9.     public WheelCollider rightWheel;
    10.     public bool motor;
    11.     public bool steering;
    12. }
    13.  
    14. public class SimpleCarController : MonoBehaviour
    15. {
    16.     public List<AxleInfo> axleInfos;
    17.     public float maxMotorTorque;
    18.     public float maxSteeringAngle;
    19.  
    20.     // finds the corresponding visual wheel
    21.     // correctly applies the transform
    22.     public void ApplyLocalPositionToVisuals(WheelCollider collider)
    23.     {
    24.         if (collider.transform.childCount == 0)
    25.         {
    26.             return;
    27.         }
    28.  
    29.         Transform visualWheel = collider.transform.GetChild(0);
    30.  
    31.         Vector3 position;
    32.         Quaternion rotation;
    33.         collider.GetWorldPose(out position, out rotation);
    34.  
    35.         visualWheel.transform.position = position;
    36.         visualWheel.transform.rotation = rotation;
    37.     }
    38.  
    39.     public void FixedUpdate()
    40.     {
    41.         float motor = maxMotorTorque * Input.GetAxis("Vertical");
    42.         float steering = maxSteeringAngle * Input.GetAxis("Horizontal");
    43.  
    44.         foreach (AxleInfo axleInfo in axleInfos)
    45.         {
    46.             if (axleInfo.steering)
    47.             {
    48.                 axleInfo.leftWheel.steerAngle = steering;
    49.                 axleInfo.rightWheel.steerAngle = steering;
    50.             }
    51.             if (axleInfo.motor)
    52.             {
    53.                 axleInfo.leftWheel.motorTorque = motor;
    54.                 axleInfo.rightWheel.motorTorque = motor;
    55.             }
    56.             ApplyLocalPositionToVisuals(axleInfo.leftWheel);
    57.             ApplyLocalPositionToVisuals(axleInfo.rightWheel);
    58.         }
    59.     }
    60. }
    help I am stuck
     
  2. xxfelixlangerxx

    xxfelixlangerxx

    Joined:
    Feb 6, 2019
    Posts:
    31