Unity. Vector3.SmoothDamp()
π Vector3.SmoothDamp()
κ²μμ λ§λ€ λ λ©μΈ μΉ΄λ©λΌκ° μ΄λ μ λ 거리λ₯Ό λκ³ νλ μ΄μ΄λ₯Ό λ°λΌ κ°κ² νλ €λ©΄, Rig μ€λΈμ νΈλ₯Ό λ§λ€μ΄μ λ©μΈ μΉ΄λ©λΌλ₯Ό νμμ λκ³ μΌμ ν 거리λ₯Ό λκ² λ§λ€μ΄ Rig μ€λΈμ νΈκ° νλ μ΄μ΄λ₯Ό λ°λΌ κ°κ² λ§λλ λ°©λ²μ΄ μλ€. νμ§λ§ μ΄κ²λ³΄λ€ λ λΆλλ¬μ΄ μμ§μμ ꡬμ¬ν΄μΌ νλ κ²½μ°κ° μλλ°, κ·Έλ λ°λ‘ Vector3.SmoothDamp()
λ₯Ό μ¬μ©νλ€.
π μ¬μ©λ²
public class ExampleClass : MonoBehaviour {
public Transform target;
public float smoothTime = 0.3F;
private Vector3 velocity = Vector3.zero;
void Update() {
Vector3 targetPosition = target.TransformPoint(new Vector3(0, 5, -10));
transform.position = Vector3.SmoothDamp(transform.position, targetPosition, ref velocity, smoothTime);
}
}
첫 λ²μ§Έ μΈμλ νμ¬ μμΉ, λ λ²μ§Έ μΈμλ λλ¬ν μμΉ, μΈ λ²μ§Έλ μ€λΈμ νΈμ λ§μ§λ§ μλ, μ¦, νμ¬ μλμ΄λ€. μ΄ λ μΈ λ²μ§Έ μΈμλ κ°μ΄ λ§€λ² μμ λκ³ λ§μ§λ§ μΈμλ νκ²μ λλ¬νκΈ° μν λλ΅μ μΈ μκ°μ΄λ€. μκ°μ΄ μ§§μ μλ‘ νκ²μ 빨리 λμ°©νλ€.
public static Vector3 SmoothDamp(Vector3 current, Vector3 target, ref Vector3 currentVelocity, float smoothTime, float maxSpeed = Mathf.Infinity, float deltaTime = Time.deltaTime);
μμμλ μμμ§λ§ λ€μ μΆκ°μ μΌλ‘ μ΅λ μλλ₯Ό μ§μ ν μ μλ€. deltaTimeμ μ΄ ν¨μκ° λ§μ§λ§μΌλ‘ νΈμΆλκ³ λμμ κ²½κ³Ό μκ°μ΄λ€. λ λ€ λν΄νΈλ‘ μ§μ λ κ² μλ€.
λκΈλ¨κΈ°κΈ°