본문 바로가기
UNITY/PROJECT

포물선 그리기 +Vector3.Dot에 대한 이해

by 램플릿 2024. 11. 22.

Vector3.Dot(throwDirection, Physics.gravity)의 역할
이 값은 던지는 방향(throwDirection)과 중력(Physics.gravity) 사이의 관계를 나타냅니다.
계산 결과:
양수: 던지는 방향이 중력 방향(아래쪽)과 어느 정도 같은 방향.
음수: 던지는 방향이 중력과 반대 방향(위쪽)을 향함.
0: 던지는 방향이 중력과 직각(수평 방향). 

 

Vector3 velocity = Vector3.zero;
        Vector3 throwDirection = target - transform.position; //목표지점과 현위치의 벡터 측정
        
        float gSquared = Physics.gravity.sqrMagnitude;  //중력벡터 제곱
        
        //발사체의 최대 속도 제곱과 목표 지점까지의 거리 벡터와 중력 벡터의 내적을 합친 값.
        float b = throwingSpeed * throwingSpeed + Vector3.Dot(throwDirection, Physics.gravity);
        
        //2차방정식의 판별식. (discriminant가 0 이상일때만 목표에 도달하는 실근이 존재.)
        float discriminant = b * b - gSquared * throwDirection.sqrMagnitude;

Dot가 음수일수록(향하는 방향이 반대일수록) 속도가 손실됨