23 lines
593 B
C#
23 lines
593 B
C#
using UnityEngine;
|
|
|
|
//검 끝에 붙일 스크립트
|
|
public class VelocityEstimator : MonoBehaviour
|
|
{
|
|
//속도값 전달용
|
|
public Vector3 Velocity { get; private set; }
|
|
|
|
private Vector3 previousPosition;
|
|
|
|
private void OnEnable()
|
|
{
|
|
previousPosition = transform.position;
|
|
}
|
|
|
|
//물리 연산 주기에 맞춰 속도 계산
|
|
private void FixedUpdate()
|
|
{
|
|
//(현재 위치 - 이전 위치) / 시간 = 속도
|
|
Velocity = (transform.position - previousPosition) / Time.fixedDeltaTime;
|
|
previousPosition = transform.position;
|
|
}
|
|
} |