Vector3.Project

jkjkbk·2023년 4월 24일
0

Unity

목록 보기
3/16
post-thumbnail

Vector3.Project

Declaration

public static Vector3 Project(Vector3 vector, Vector3 onNormal);

Parameters

Vector3 vector

사상시킬 벡터

Vector3 onNormal

사상 기준이 되는 벡터. 길이가 1이 아니더라도 길이가 1인 벡터(nomalized)와 return이 다르지 않다

Returns

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);   
    }
}

0개의 댓글