- Home /
InverseTransformDirection and TransformDirection
I am now making a ladder climbing feature and I have a problem about direction. So I try to test InverseTransformDirection function and TransformDirection function with an empty gameObject that has (0,270,0) Rotation(shown in inspector). Here is the code.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class char_control : MonoBehaviour
{
public Transform testobj;
public Vector3 localdir;
public Vector3 worlddir;
public Vector3 localdirResult;
public Vector3 worlddirResult;
void Update()
{
worlddirResult = testobj.TransformDirection(localdir);
localdirResult = testobj.InverseTransformDirection(worlddir);
}
}
And this is the value that the functions return why the function return weird z value in WorldirResult when I input z =1 in Localdir,I think z value should be 0. this is the inspector of Testobj
Rotation and direction are very different. The direction is just represented by 0-1 on each axis. So 0,1,0 would be Vector3.up. Whereas for the model to face upwards, you would need a rotation of -90,0,0. Another example is that a left direction is -1,0,0 but for an entity to face left, it would need a rotation of 0,-90,0. So trying to get direction the way you are doesn't really make sense. Besides, if done properly your directions should be Player.transform.up, and Ladder.transform.up, or Player.transform.forward, etc. Like if you wanted the player to rotate towards the opposite facing direction of the ladder, you'd want the player's forward direction to be -Ladder.transform.forward.
Answer by mateusthiago · Jul 22, 2020 at 02:04 PM
That weird number actually means something that could be considered 0, as it is a product of floating point imprecision. That ending with e-n means that number is actually multiplied by 10 to the -nth power, or 0.(n zeroes)1192093 in the case of your number. See these for a better understanding: https://sciencing.com/end-number-mean-7430704.html https://floating-point-gui.de/