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
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Articulated steering

Discussion in 'Scripting' started by OctoMan, Mar 20, 2018.

  1. OctoMan

    OctoMan

    Joined:
    May 10, 2014
    Posts:
    167
    Hi community,

    currectly i struggle with the calculation and usage of articulated steering on a vehicle.

    articulated steering.png

    1.) So when i have a specific rotation angle, lets say 15 degrees, i would like to know how the vehicle has to move in the correct radius and how to calculate the rotation point, if needed?

    2.) Which angle is truely necessary and how do i get it the best way?

    I don't like to use wheelcollider or such.

    I hope i find some help here.

    Cheers OctoMan
     
  2. OctoMan

    OctoMan

    Joined:
    May 10, 2014
    Posts:
    167
    Actually i made a step forward in calculating the steering angle.
    Code (csharp):
    1.  
    2. Vector3 targetDir = rotAxis.transform.position - transform.position;
    3. targetDir = rotAxis.transform.InverseTransformDirection(targetDir);
    4.  
    5. steerAngle = (Mathf.Atan2(targetDir.y, targetDir.x) * Mathf.Rad2Deg) -90;
    6.  
    7. Debug.Log(steerAngle);
    8.  
    So i have a positive and negative angle now. Next step is getting the rotation Radius and set the vector for the rotation anyhow.
     
  3. OctoMan

    OctoMan

    Joined:
    May 10, 2014
    Posts:
    167
    So i was reading alot about possiblities to calculate R.
    Since Y is know now, and L is measurable. articulated steering2.png
     
  4. OctoMan

    OctoMan

    Joined:
    May 10, 2014
    Posts:
    167
    By using the function
    tan y = l / r
    and turning it because r is requested
    r = l / tan y

    So to get L i used
    Code (csharp):
    1.  
    2. float length = Vector3.Distance(transform.position,rotAxis.transform.position);
    3.  
    Then filled the Data into the formula:
    Code (csharp):
    1.  
    2. float Radius =  length / Mathf.Tan(steerAngle);
    3.  
    But when i debug that the numbers are totally wrong. When both parts are straight it should return 0, but it does something like -106.xxxx.