Search Unity

InverseTransformDirection - Odd behaviour on x axis

Discussion in 'Scripting' started by ismaelflorit, Jun 19, 2019.

  1. ismaelflorit

    ismaelflorit

    Joined:
    Apr 16, 2019
    Posts:
    38
    Hello everyone,

    I'm currently trying to read pseudo lateral G Forces of a vehicle. I know that using InverseTransformDirection of the velocity vector I can get the position of the body relative to self:

    Code (CSharp):
    1.         lateralVelocity = transform.InverseTransformDirection(rigidbody.velocity).x;
    2.  
    My understanding of the x axis is that left is negative, and right is positive.

    The Problem

    At low speeds the velocity reads correctly: left is negative, right is positive. However once the vehicle picks up speed, when turning sharply it will read in the opposite direction!

    Has anyone come across this before? I feel like there's probably something daft that I'm missing.

    Thanks for reading,
    Ismael