Search Unity

Quick Question about Vectors

Discussion in 'Scripting' started by Deleted User, Jul 5, 2015.

  1. Deleted User

    Deleted User

    Guest

    Hi, i got one Vector who need be converted back to the raw force.

    This is how the vector is working:
    Code (Csharp):
    1. ThisAwesomeVector = Transform.TransformDirection(ThisAwesomeVector)
    ThisAwesomeVector looks something like (0.18592, 0f, -0.42398)
    How can got it back to (0f, 0f, 5) like in the Force, i want add a 2nd Vector3 who present the relative direction just on x and z.

    Like for exemple when i press the W key this vector changes to (0f, 0f, 4), and on the S key we got one (0f, 0f, -4), with A and D the same on the x direction without changing the the original vector3 (ThisAwesomeVector).

    Thanks
     
    Last edited by a moderator: Jul 5, 2015
  2. HiddenMonk

    HiddenMonk

    Joined:
    Dec 19, 2014
    Posts:
    987
    maybe transform.InverseTransformDirection(vector3);
     
  3. Deleted User

    Deleted User

    Guest

    nope... dont works in my case
     
    Last edited by a moderator: Jul 5, 2015
  4. HiddenMonk

    HiddenMonk

    Joined:
    Dec 19, 2014
    Posts:
    987
    you are doing
    Code (CSharp):
    1. ThisAwesomeVector = Transform.TransformDirection(ThisAwesomeVector)
    but shouldnt it actually be something like
    Code (CSharp):
    1. ThisAwesomeVector = myTransform.TransformDirection(ThisAwesomeVector)
    (you can also do just transform with the lowercase t).

    TransformDirection brings the vector from local space, to world space based on the transform.
    InverseTransformDirection brings the vector from world, to the transforms local space, which is what you want.

    I never tried it, but maybe you are doing "Transform.InverseTransformDirection", which might default to world space or something, where you actually want "myTransform.InverseTransformDirection" so that it brings it to the myTransform localSpace (you can also do just transform with the lowercase t).
     
  5. Deleted User

    Deleted User

    Guest

    Well, i try that but it did not work.
    What i try to do is when i got force forward, with ore without input to get a bool (imMovingForward) true.

    The point is i just looking for the Force Vector, maybe there is a other possible solution to get this working.
    But thanks for your help.
     
  6. JamesLeeNZ

    JamesLeeNZ

    Joined:
    Nov 15, 2011
    Posts:
    5,616
    Sounds like you are trying to determine the velocity in local space?
     
  7. Deleted User

    Deleted User

    Guest

    Yea, how can i do that?
     
  8. JamesLeeNZ

    JamesLeeNZ

    Joined:
    Nov 15, 2011
    Posts:
    5,616
  9. Deleted User

    Deleted User

    Guest

    Alright, i got it!

    ThisAwesomeVector = Transform.InverseTransformVector(MotorForceVector);

    Thank you,
     
    JamesLeeNZ likes this.