Unity. Mathf.SmoothDampAngle()
π Mathf.SmoothDampAngle()
μκ°μ΄ μ§λ¨μ λ°λΌ λͺ©ν κ°λλ‘ ν₯νλ ν¨μλ€.
π μ¬μ©λ²
using UnityEngine;
using System.Collections;
public class ExampleClass : MonoBehaviour {
public Transform target; //λλ¬νλ €λ μμΉ
public float smooth = 0.3f; //νμΌμ λμ°©νλ λλ΅μ μΈ μκ°
public float distance = 5.0f;
private float yVelocity = 0.0f; //νμ¬ μλ λ΄μ λ³μ
void Update() {
float yAngle = Mathf.SmoothDampAngle(transform.eulerAngles.y, target.eulerAngles.y, ref yVelocity, smooth);
Vector3 position = target.position;
position += Quaternion.Euler(0, yAngle, 0) * new Vector3(0, 0, -distance);
transform.position = position;
transform.LookAt(target);
}
}
μ λν° κ³΅μ λ¬Έμμμ κ°μ Έμ΄!
SmoothDampAngleμ μΈμλ νμ¬ μμΉκ°, λλ¬νλ €λ μμΉ, νμ¬ μλ, νκ²μ λμ°©νλ μκ°, μ νμ μΌλ‘ μ΅λ μλμ κ²½κ³Ό μκ°μ΄ μλ€. μμ λ€ κ°λ§ μ κ²½μ°λ©΄ λ λ―!
float yAngle = Mathf.SmoothDampAngle(transform.eulerAngles.y, target.eulerAngles.y, ref yVelocity, smooth);
μ 보면 transform.eulerAngles.yμμ target.eulerAngles.yμ΄ κ°λλ‘ smooth μκ° λμ λ³κ²½λλ κ±Έ μ μ μλ€! λ°μ μ½λλ μ λͺ¨λ₯΄κ² μ
λκΈλ¨κΈ°κΈ°