DDD-43 파도에 따른 배 오프셋 추가
This commit is contained in:
parent
1b45fab5eb
commit
241a2fc51d
@ -125,6 +125,12 @@ MonoBehaviour:
|
|||||||
accelTiltSpeed: 10
|
accelTiltSpeed: 10
|
||||||
springStiffness: 30
|
springStiffness: 30
|
||||||
springDamping: 15
|
springDamping: 15
|
||||||
|
minSpeedWaveHeight: 0.2
|
||||||
|
maxSpeedWaveHeight: 0.05
|
||||||
|
baseWaveFrequency: 1
|
||||||
|
speedWaveMultiplier: 5
|
||||||
|
randomWaveOffset: 0.5
|
||||||
|
waveUnitSpeed: 10
|
||||||
meshObjectName: Ship_Mesh
|
meshObjectName: Ship_Mesh
|
||||||
--- !u!1 &6407855916708530114
|
--- !u!1 &6407855916708530114
|
||||||
GameObject:
|
GameObject:
|
||||||
|
@ -10,12 +10,15 @@ public class VoyagePlayerShipMovement : MonoBehaviour
|
|||||||
[SerializeField] private float accelerationRate = 1f;
|
[SerializeField] private float accelerationRate = 1f;
|
||||||
[SerializeField] private float minSpeedThreshold = 0.1f;
|
[SerializeField] private float minSpeedThreshold = 0.1f;
|
||||||
[SerializeField] private float dragFactor = 0.98f;
|
[SerializeField] private float dragFactor = 0.98f;
|
||||||
|
private Vector3 currentVelocity;
|
||||||
|
private Vector2 currentInput;
|
||||||
|
private float targetSpeed;
|
||||||
|
private float currentSpeed;
|
||||||
|
|
||||||
[Header("Turn Settings")]
|
[Header("Turn Settings")]
|
||||||
[SerializeField] private float turnSpeedPenalty = 0.5f; // 선회 시 감속 정도 (0: 감속 없음, 1: 완전 정지)
|
[SerializeField] private float turnSpeedPenalty = 0.5f; // 선회 시 감속 정도 (0: 감속 없음, 1: 완전 정지)
|
||||||
[SerializeField] private float maxTurnAngle = 180f; // 최대 감속이 적용되는 각도
|
[SerializeField] private float maxTurnAngle = 180f; // 최대 감속이 적용되는 각도
|
||||||
|
|
||||||
|
|
||||||
#if UNITY_EDITOR
|
#if UNITY_EDITOR
|
||||||
[Header("Debug Settings")]
|
[Header("Debug Settings")]
|
||||||
[SerializeField] private bool showDebugLines = true;
|
[SerializeField] private bool showDebugLines = true;
|
||||||
@ -28,18 +31,18 @@ public class VoyagePlayerShipMovement : MonoBehaviour
|
|||||||
private LineRenderer inputDirectionLine;
|
private LineRenderer inputDirectionLine;
|
||||||
private bool lineRendererCreated = false;
|
private bool lineRendererCreated = false;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
private Vector3 currentVelocity;
|
|
||||||
private Vector2 currentInput;
|
|
||||||
private float targetSpeed;
|
|
||||||
private float currentSpeed;
|
|
||||||
|
|
||||||
|
// Rotation Tilt
|
||||||
[Header("Rotation Tilt Settings")]
|
[Header("Rotation Tilt Settings")]
|
||||||
[SerializeField] private float maxRotationTiltAngle = 15f;
|
[SerializeField] private float maxRotationTiltAngle = 15f;
|
||||||
[SerializeField] private float rotationTiltSpeed = 5f;
|
[SerializeField] private float rotationTiltSpeed = 5f;
|
||||||
[SerializeField] private float RotationTiltReturnSpeed = 3f; // 원래 자세로 돌아오는 속도
|
[SerializeField] private float RotationTiltReturnSpeed = 3f; // 원래 자세로 돌아오는 속도
|
||||||
[SerializeField] private float angularVelocityMultiplier = 2f; // 각속도 영향력
|
[SerializeField] private float angularVelocityMultiplier = 2f; // 각속도 영향력
|
||||||
|
private float _currentRotationTilt = 0f;
|
||||||
|
private float _lastRotationY; // 이전 프레임의 Y축 회전값
|
||||||
|
private float _currentAngularVelocity; // 현재 각속도
|
||||||
|
|
||||||
|
// Acceleration Tilt
|
||||||
[Header("Acceleration Tilt Settings")]
|
[Header("Acceleration Tilt Settings")]
|
||||||
[SerializeField] private float maxAccelTiltAngle = 15f; // 최대 가속 틸트 각도
|
[SerializeField] private float maxAccelTiltAngle = 15f; // 최대 가속 틸트 각도
|
||||||
[SerializeField] private float accelTiltForce = 15f; // 틸트 강도
|
[SerializeField] private float accelTiltForce = 15f; // 틸트 강도
|
||||||
@ -47,21 +50,31 @@ public class VoyagePlayerShipMovement : MonoBehaviour
|
|||||||
[SerializeField] private float accelTiltSpeed = 10f; // 스프링 보간속도
|
[SerializeField] private float accelTiltSpeed = 10f; // 스프링 보간속도
|
||||||
[SerializeField] private float springStiffness = 30f; // 스프링 강성
|
[SerializeField] private float springStiffness = 30f; // 스프링 강성
|
||||||
[SerializeField] private float springDamping = 15f; // 스프링 감쇠
|
[SerializeField] private float springDamping = 15f; // 스프링 감쇠
|
||||||
|
|
||||||
[Header("Mesh Settings")]
|
|
||||||
[SerializeField] private string meshObjectName = "Ship_Mesh";
|
|
||||||
|
|
||||||
private Transform _meshTransform;
|
|
||||||
// Rotation Tilt
|
|
||||||
private float _currentRotationTilt = 0f;
|
|
||||||
private float _lastRotationY; // 이전 프레임의 Y축 회전값
|
|
||||||
private float _currentAngularVelocity; // 현재 각속도
|
|
||||||
// Acceleration Tilt
|
|
||||||
private float _currentAccelTilt;
|
private float _currentAccelTilt;
|
||||||
private float _accelTiltVelocity;
|
private float _accelTiltVelocity;
|
||||||
private float _prevSpeed;
|
private float _prevSpeed;
|
||||||
|
|
||||||
|
// Wave offset
|
||||||
|
[Header("Wave Settings")]
|
||||||
|
[SerializeField] private float minSpeedWaveHeight = 0.2f; // 기본 파도 높이
|
||||||
|
[SerializeField] private float maxSpeedWaveHeight = 0.05f; // 기준 속력일때 파도 높이
|
||||||
|
|
||||||
|
[SerializeField] private float baseWaveFrequency = 1f; // 기본 파도 주기
|
||||||
|
[SerializeField] private float speedWaveMultiplier = 5f; // 속도에 따른 주기 증가 계수
|
||||||
|
[SerializeField] private float randomWaveOffset = 0.5f; // 랜덤 오프셋 범위
|
||||||
|
[SerializeField] private float waveUnitSpeed = 10f; // 기준 속력
|
||||||
|
private float _waveTime;
|
||||||
|
private float _waveRandomOffset;
|
||||||
|
private float currentWaveHeight;
|
||||||
|
|
||||||
|
|
||||||
|
[Header("Mesh Settings")]
|
||||||
|
[SerializeField] private string meshObjectName = "Ship_Mesh";
|
||||||
|
private Transform _meshTransform;
|
||||||
|
|
||||||
|
|
||||||
private Quaternion _originalMeshRotation;
|
private Quaternion _originalMeshRotation;
|
||||||
|
private Vector3 _originalMeshPosition;
|
||||||
|
|
||||||
private void Start()
|
private void Start()
|
||||||
{
|
{
|
||||||
@ -72,9 +85,12 @@ public class VoyagePlayerShipMovement : MonoBehaviour
|
|||||||
enabled = false;
|
enabled = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_originalMeshPosition = _meshTransform.localPosition;
|
||||||
_originalMeshRotation = _meshTransform.localRotation;
|
_originalMeshRotation = _meshTransform.localRotation;
|
||||||
_lastRotationY = transform.eulerAngles.y;
|
_lastRotationY = transform.eulerAngles.y;
|
||||||
|
_waveTime = 0f;
|
||||||
|
_waveRandomOffset = Random.Range(-randomWaveOffset, randomWaveOffset);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void FixedUpdate()
|
private void FixedUpdate()
|
||||||
@ -92,10 +108,13 @@ public class VoyagePlayerShipMovement : MonoBehaviour
|
|||||||
ApplyDrag();
|
ApplyDrag();
|
||||||
ApplyMovement();
|
ApplyMovement();
|
||||||
|
|
||||||
// Cosmetic Mesh Tilting
|
// Cosmetic mesh tilting
|
||||||
UpdateMeshRotationTilt();
|
UpdateMeshRotationTilt();
|
||||||
UpdateAccelerationTilt();
|
UpdateAccelerationTilt();
|
||||||
ApplyMeshTilt();
|
ApplyMeshTilt();
|
||||||
|
// Cosmetic mesh wave offset
|
||||||
|
UpdateWaveMotion();
|
||||||
|
ApplyMeshOffset();
|
||||||
|
|
||||||
#if UNITY_EDITOR
|
#if UNITY_EDITOR
|
||||||
if (showDebugLines)
|
if (showDebugLines)
|
||||||
@ -207,7 +226,6 @@ public class VoyagePlayerShipMovement : MonoBehaviour
|
|||||||
_currentAccelTilt = Mathf.Clamp(_currentAccelTilt, -maxAccelTiltAngle, maxAccelTiltAngle);
|
_currentAccelTilt = Mathf.Clamp(_currentAccelTilt, -maxAccelTiltAngle, maxAccelTiltAngle);
|
||||||
|
|
||||||
_prevSpeed = currentSpeed;
|
_prevSpeed = currentSpeed;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ApplyMeshTilt()
|
private void ApplyMeshTilt()
|
||||||
@ -223,7 +241,28 @@ public class VoyagePlayerShipMovement : MonoBehaviour
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void UpdateWaveMotion()
|
||||||
|
{
|
||||||
|
if (_meshTransform is null) return;
|
||||||
|
|
||||||
|
// 현재 속도에 비례하여 파도 주기 조절
|
||||||
|
float waveSpeedFactor = 1f + (currentSpeed / waveUnitSpeed) * speedWaveMultiplier;
|
||||||
|
_waveTime += Time.fixedDeltaTime * baseWaveFrequency * waveSpeedFactor;
|
||||||
|
float currentSpeedByUnit = currentSpeed / waveUnitSpeed;
|
||||||
|
currentSpeedByUnit = Mathf.Clamp01(currentSpeedByUnit);
|
||||||
|
float waveHeight = Mathf.Lerp(minSpeedWaveHeight, maxSpeedWaveHeight, currentSpeedByUnit);
|
||||||
|
|
||||||
|
currentWaveHeight = waveHeight * Mathf.Sin(_waveTime + _waveRandomOffset);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ApplyMeshOffset()
|
||||||
|
{
|
||||||
|
if (_meshTransform is null) return;
|
||||||
|
|
||||||
|
Vector3 position = _originalMeshPosition + (Vector3.up * currentWaveHeight);
|
||||||
|
_meshTransform.localPosition = position;
|
||||||
|
}
|
||||||
|
|
||||||
private void ApplyDrag()
|
private void ApplyDrag()
|
||||||
{
|
{
|
||||||
currentSpeed *= dragFactor;
|
currentSpeed *= dragFactor;
|
||||||
|
Loading…
Reference in New Issue
Block a user