Bezi回来了
This commit is contained in:
@@ -47,9 +47,28 @@ namespace Cielonos.MainGame.Characters
|
||||
}
|
||||
}
|
||||
|
||||
public void TurnToTarget(CharacterBase target, float duration = 0.2f)
|
||||
public void SmartTurnToTarget(CharacterBase target, float maxTurnAngle = 150f)
|
||||
{
|
||||
characterTransform.DOLookAt(target.transform.position, duration, AxisConstraint.Y).Play();
|
||||
Vector3 directionToTarget = (target.centerPoint.position - owner.centerPoint.position).Flatten();
|
||||
if (directionToTarget.sqrMagnitude < 0.001f) return;
|
||||
|
||||
float angleToTarget = Vector3.SignedAngle(owner.transform.forward, directionToTarget, Vector3.up);
|
||||
float absAngle = Mathf.Abs(angleToTarget);
|
||||
|
||||
// 超过最大角度不转身
|
||||
if (absAngle > maxTurnAngle) return;
|
||||
|
||||
// 小角度瞬间转身
|
||||
if (absAngle <= 45f)
|
||||
{
|
||||
owner.transform.rotation = Quaternion.LookRotation(directionToTarget);
|
||||
}
|
||||
// 大角度平滑转身
|
||||
else
|
||||
{
|
||||
float duration = Mathf.Lerp(0.1f, 0.2f, (absAngle - 45f) / 135f);
|
||||
owner.transform.DORotateQuaternion(Quaternion.LookRotation(directionToTarget), duration).Play();
|
||||
}
|
||||
}
|
||||
|
||||
public void TurnToTargetByAngle(CharacterBase target, float angularSpeed)
|
||||
|
||||
Reference in New Issue
Block a user