player_polishing #7

Merged
Jeonghyeon merged 5 commits from player_polishing into develop 2025-07-17 02:45:10 +00:00
2 changed files with 27 additions and 9 deletions
Showing only changes of commit 47ab5d8a0c - Show all commits

View File

@ -24,6 +24,18 @@ public class RestaurantPlayerDataSo : ScriptableObject
[Range(0f, 3f), Tooltip("슬라이딩 보정 제곱\n낮을수록 슬라이딩이 잘 됨")] [Range(0f, 3f), Tooltip("슬라이딩 보정 제곱\n낮을수록 슬라이딩이 잘 됨")]
public float SlidingThreshold = 0.5f; public float SlidingThreshold = 0.5f;
public float VelocityMinThreshold = 0.01f;
public float BoxCastExtentScale = 0.95f;
public float MinSlideFactorThreshold = 0.05f;
// 디버그
public int InputLineSortingOrder = 10;
public int VelocityLineSortingOrder = 9;
public float InputLineWidth = 0.1f;
public float VelocityLineWidth = 0.2f;
public float InputLineLength = 1.5f;
public float VelocityLineScale = 0.5f;
public string WalkingSfxName; public string WalkingSfxName;
public string DashSfxName; public string DashSfxName;

View File

@ -27,6 +27,10 @@ public class RestaurantPlayerMovement : RestaurantCharacterMovement
public Action<bool> OnMoving; public Action<bool> OnMoving;
public Action<float> OnDashing; public Action<float> OnDashing;
private const string InputDebugLineRenderer = "DebugLine_Input";
private const string VelocityDebugLineRenderer = "DebugLine_Velocity";
private const string SpriteDefaultShader = "Sprites/Default";
private void Awake() private void Awake()
{ {
_rigidbody = GetComponent<Rigidbody>(); _rigidbody = GetComponent<Rigidbody>();
@ -76,16 +80,17 @@ private void OnDestroy()
} }
} }
#if UNITY_EDITOR
private void DrawLineDebug() private void DrawLineDebug()
{ {
Vector3 origin = transform.position; Vector3 origin = transform.position;
if (_inputDirection != Vector3.zero) if (_inputDirection != Vector3.zero)
{ {
Vector3 target = origin + _inputDirection.normalized * 1.5f; Vector3 target = origin + _inputDirection.normalized * _playerDataSo.InputLineLength;
if (_inputLineRenderer == null) if (_inputLineRenderer == null)
{ {
_inputLineRenderer = CreateOrGetDebugLineRenderer("DebugLine_Input", 10, 0.1f, Color.blue); _inputLineRenderer = CreateOrGetDebugLineRenderer(InputDebugLineRenderer, _playerDataSo.InputLineSortingOrder, _playerDataSo.InputLineWidth, Color.blue);
} }
UpdateLineRenderer(_inputLineRenderer, origin, target); UpdateLineRenderer(_inputLineRenderer, origin, target);
@ -97,13 +102,13 @@ private void DrawLineDebug()
} }
float speed = _currentVelocity.magnitude; float speed = _currentVelocity.magnitude;
if (speed > 0.01f) if (speed > _playerDataSo.VelocityMinThreshold)
{ {
Vector3 target = origin + _currentVelocity.normalized * (speed * 0.5f); Vector3 target = origin + _currentVelocity.normalized * (speed * _playerDataSo.VelocityLineScale);
if (_velocityLineRenderer == null) if (_velocityLineRenderer == null)
{ {
_velocityLineRenderer = CreateOrGetDebugLineRenderer("DebugLine_Velocity", 9, 0.2f, Color.red); _velocityLineRenderer = CreateOrGetDebugLineRenderer(VelocityDebugLineRenderer, _playerDataSo.VelocityLineSortingOrder, _playerDataSo.VelocityLineWidth, Color.red);
} }
UpdateLineRenderer(_velocityLineRenderer, origin, target); UpdateLineRenderer(_velocityLineRenderer, origin, target);
@ -134,7 +139,7 @@ private LineRenderer CreateOrGetDebugLineRenderer(string name, int sortingIndex,
var lineRenderer = newGameObject.AddComponent<LineRenderer>(); var lineRenderer = newGameObject.AddComponent<LineRenderer>();
lineRenderer.positionCount = 2; lineRenderer.positionCount = 2;
lineRenderer.material = new Material(Shader.Find("Sprites/Default")); // URP 호환 lineRenderer.material = new Material(Shader.Find(SpriteDefaultShader)); // URP 호환
lineRenderer.sortingOrder = sortingIndex; lineRenderer.sortingOrder = sortingIndex;
lineRenderer.startWidth = lineRenderer.endWidth = width; lineRenderer.startWidth = lineRenderer.endWidth = width;
lineRenderer.startColor = lineRenderer.endColor = color; lineRenderer.startColor = lineRenderer.endColor = color;
@ -148,6 +153,7 @@ private void UpdateLineRenderer(LineRenderer lr, Vector3 start, Vector3 end)
lr.SetPosition(0, start); lr.SetPosition(0, start);
lr.SetPosition(1, end); lr.SetPosition(1, end);
} }
#endif
public void SetCurrentDirection(Vector3 normalDirection) public void SetCurrentDirection(Vector3 normalDirection)
{ {
@ -198,14 +204,14 @@ private Vector3 GetSlideAdjustedDirection(Vector3 inputDirection)
: _boxCollider.bounds.size.z; : _boxCollider.bounds.size.z;
int layerMask = ~_playerDataSo.IgnoreSlidingLayerMask; int layerMask = ~_playerDataSo.IgnoreSlidingLayerMask;
if (Physics.BoxCast(origin, halfExtents * 0.95f, inputDirection, out RaycastHit hit, rotation, distance, layerMask)) if (Physics.BoxCast(origin, halfExtents * _playerDataSo.BoxCastExtentScale, inputDirection, out RaycastHit hit, rotation, distance, layerMask))
{ {
Review

매직넘버 제거하고 파라미터화 혹은 프라이빗 필드, 혹은 제대로된 이름이 붙은 지역변수로 변경할것.

매직넘버 제거하고 파라미터화 혹은 프라이빗 필드, 혹은 제대로된 이름이 붙은 지역변수로 변경할것.
Vector3 slide = Vector3.ProjectOnPlane(inputDirection, hit.normal).normalized; Vector3 slide = Vector3.ProjectOnPlane(inputDirection, hit.normal).normalized;
float dot = Vector3.Dot(inputDirection.normalized, hit.normal); float dot = Vector3.Dot(inputDirection.normalized, hit.normal);
float slideFactor = Mathf.Pow(1f - Mathf.Abs(dot), _playerDataSo.SlidingThreshold); float slideFactor = Mathf.Pow(1f - Mathf.Abs(dot), _playerDataSo.SlidingThreshold);
if (slideFactor < 0.05f) return Vector3.zero; if (slideFactor < _playerDataSo.MinSlideFactorThreshold) return Vector3.zero;
return slide * slideFactor; return slide * slideFactor;
} }