public static Vector3 Project(Vector3 vector, Vector3 onNormal);
Vector3 vector
사상시킬 벡터
Vector3 onNormal
사상 기준이 되는 벡터. 길이가 1이 아니더라도 길이가 1인 벡터(nomalized)와 return이 다르지 않다
noNormal 벡터에 사상시킨 결과 "벡터"가 반환됨
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Vector3ProjectTest : MonoBehaviour
{
public Transform NormalVectorObject;
public Transform Target;
public Vector3 TargetOriginPosition;
public Vector3 ProjectedVector;
void Start()
{
TargetOriginPosition = Target.position;
Vector3 dir = NormalVectorObject.up;
ProjectedVector = Vector3.Project(Target.position, dir);
Target.position = ProjectedVector;
}
void Update()
{
Debug.DrawRay(NormalVectorObject.position + ProjectedVector, NormalVectorObject.up * 100f, Color.red);
Debug.DrawRay(NormalVectorObject.position, TargetOriginPosition - NormalVectorObject.position, Color.yellow);
Debug.DrawRay(NormalVectorObject.position, ProjectedVector, Color.green);
}
}