반응형
UnitMovement.cs
private void UpdateIdleRotation ()
{
if (!canIdleRotate || nextRotationTarget == Quaternion.identity) //can the unit rotate when idle + there's a valid rotation target
return;
if (IdleLookAtTransform != null) //if there's a target object to look at.
nextRotationTarget = RTSHelper.GetLookRotation(transform, IdleLookAtTransform.position, true); //keep updating the rotation target as the target object might keep changing position
if (smoothIdleRotation)
transform.rotation = Quaternion.Slerp(transform.rotation, nextRotationTarget, Time.deltaTime * idleAngularSpeed);
else
transform.rotation = nextRotationTarget;
}
RTSHelper.cs
public static Quaternion GetLookRotation(Transform transform, Vector3 targetPosition, bool reversed = false, bool fixYRotation = true)
{
if (reversed)
targetPosition = transform.position - targetPosition;
else
targetPosition -= transform.position;
if(fixYRotation == true)
targetPosition.y = 0;
if (targetPosition != Vector3.zero)
return Quaternion.LookRotation(targetPosition);
else
return transform.rotation;
}
reverse : 반대쪽을 향함
fixRotation : 위아래로도 방향에 맞추어서 회전
반응형
'Unity > Asset 분석' 카테고리의 다른 글
[Easy Roads 3D Pro] 교차로 만들기 (0) | 2021.07.04 |
---|---|
[Easy Road 3D Pro] 도로 만들기 (0) | 2021.07.04 |
[Stylelized Projectile] 주요 Method (0) | 2021.06.20 |
[Volumetric Fog] 안개속에서 빛나는 Light 연출 (0) | 2021.06.13 |
[Lux Water] 물 속 구현 (0) | 2021.06.13 |