Version: 2022.1
언어: 한국어

Mathf.SmoothDampAngle

매뉴얼로 전환
public static float SmoothDampAngle (float current, float target, ref float currentVelocity, float smoothTime, float maxSpeed= Mathf.Infinity, float deltaTime= Time.deltaTime);

파라미터

current The current position.
target The position we are trying to reach.
currentVelocity The current velocity, this value is modified by the function every time you call it.
smoothTime Approximately the time it will take to reach the target. A smaller value will reach the target faster.
maxSpeed Optionally allows you to clamp the maximum speed.
deltaTime The time since the last call to this function. By default Time.deltaTime.

설명

Gradually changes an angle given in degrees towards a desired goal angle over time.

The value is smoothed by some spring-damper like function. The function can be used to smooth any kind of value, positions, colors, scalars. The most common use is for smoothing a follow camera.

using UnityEngine;

public class Example : MonoBehaviour { //A simple smooth follow camera, // that follows the targets forward direction

Transform target; float smooth = 0.3f; float distance = 5.0f; float yVelocity = 0.0f;

void Update() { // Damp angle from current y-angle towards target y-angle float yAngle = Mathf.SmoothDampAngle(transform.eulerAngles.y, target.eulerAngles.y, ref yVelocity, smooth); // Position at the target Vector3 position = target.position; // Then offset by distance behind the new angle position += Quaternion.Euler(0, yAngle, 0) * new Vector3(0, 0, -distance); // Apply the position transform.position = position;

// Look at the target transform.LookAt(target); } }