Transform.TransformDirection

 => Local공간에서 World공간으로 방향 Vector로 변환한다.

 => Scale이나 position의 영향을 받지않는다.

 

 

code

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Hero2 : MonoBehaviour
{
    public Transform target;

    public Vector3 testWorldPosition;
    public Vector3 testLocalPosition;

    public Vector3 p1;
    public Vector3 p2;
    public Vector3 p3;
    public Vector3 p4;


    private void OnDrawGizmos()
    {
        this.testWorldPosition = this.transform.position;
        this.testLocalPosition = this.transform.localPosition;

        Vector3 offset = target.transform.position;

        Gizmos.color = Color.blue;
        Gizmos.DrawLine(this.transform.position, 
                        this.transform.position + this.transform.forward * offset.z);

        Gizmos.color = Color.red;
        Gizmos.DrawLine(this.transform.position, 
                        this.transform.position + target.transform.right * offset.x);
        
        Gizmos.color = Color.yellow;
        var tv = this.transform.forward * offset.z + target.transform.right * offset.x;
        Gizmos.DrawLine(this.transform.position, this.transform.position + tv);
        

        Gizmos.color = Color.white;
        p1 = this.transform.TransformDirection(offset);
        Gizmos.DrawLine(Vector3.zero, p1);
        
        /**
        Gizmos.color = Color.magenta;
        Vector3 tv2 = Vector3.forward * offset.z + Vector3.right * offset.x;
        Gizmos.DrawLine(this.transform.position, this.transform.position + tv2);
        
        
        Gizmos.color = Color.green;
        p3 = this.transform.InverseTransformPoint(offset);
        var tv3 = this.transform.forward * p3.z + this.transform.right * p3.x;
        Gizmos.DrawLine(this.transform.position, this.transform.position + tv3);
        
        Gizmos.color = Color.cyan;
        p4 = this.transform.TransformPoint(offset);
        Gizmos.DrawLine(Vector3.zero, p4);
        **/
    } 
}

+ Recent posts