#19 Rockfall 바닥 뚫는 버그 및 무한루프 버그 수정

+ DamageableProps Enable()함수에 Max체력으로 변경하는 로직 추거

Closes #19
This commit is contained in:
Nam Tae Gun 2024-06-16 16:55:58 +09:00
parent 1ee1df12dd
commit d76915283a
3 changed files with 70 additions and 71 deletions

View File

@ -1,3 +1,4 @@
using System;
using BlueWater.Audios;
using BlueWater.Interfaces;
using Sirenix.OdinInspector;
@ -22,7 +23,12 @@ namespace BlueWater
private ParticleSystem _dieParticle;
protected Transform SpawnLocation;
protected virtual void OnEnable()
{
SetCurrentHealthPoint(MaxHealthPoint);
}
public virtual void SetCurrentHealthPoint(int changedHealthPoint)
{
CurrentHealthPoint = changedHealthPoint;

View File

@ -1,4 +1,3 @@
using System;
using System.Collections;
using BlueWater.Audios;
using BlueWater.Interfaces;
@ -12,9 +11,6 @@ namespace BlueWater
public class Rockfall : DamageableProps
{
[Title("컴포넌트")]
[SerializeField]
private Rigidbody _rigidbody;
[SerializeField, Required]
private SphereCollider _sphereCollider;
@ -32,8 +28,8 @@ namespace BlueWater
[SerializeField]
private LayerMask _groundLayer;
[SerializeField, Range(0f, 1f)]
private float _checkDistance = 0.1f;
[SerializeField, Range(0f, 5f)]
private float _fallTime = 1f;
[SerializeField, Range(0, 5)]
private int _attackDamage = 1;
@ -44,89 +40,84 @@ namespace BlueWater
[SerializeField]
private ParticleSystem _groundCrashParticle;
private Collider[] _hitColliders = new Collider[4];
private Collider[] _hitColliders;
private RaycastHit _raycastHit;
private float _startDistance = float.PositiveInfinity;
private bool _isGrounded;
private Vector3 _startPosition;
private Vector3 _endPosition;
private bool _isAttacked;
// Hashes
private static readonly int _fillHash = Shader.PropertyToID("_Fill");
private void OnDrawGizmos()
{
Debug.DrawRay(transform.position, Vector3.down * _checkDistance, _isGrounded ? Color.blue : Color.red);
}
private void Start()
private IEnumerator Start()
{
_sphereCollider.enabled = false;
_startPosition = transform.position;
SpawnLocation = MapManager.Instance.SandMoleMapController.ParticleInstantiateLocation;
if (!Physics.Raycast(transform.position, Vector3.down, out _raycastHit, 10f, _groundLayer))
{
Debug.LogError("땅을 감지하지 못하는 버그");
return;
}
_hitColliders = new Collider[4];
BasicSetting();
ShowIndicator();
_startDistance = _raycastHit.distance;
}
private void FixedUpdate()
{
if (!Physics.Raycast(transform.position, Vector3.down, out _raycastHit, 10f, _groundLayer))
if (!Physics.Raycast(transform.position, Vector3.down, out _raycastHit, 50f, _groundLayer))
{
Debug.LogError("땅을 감지하지 못하는 버그");
return;
yield break;
}
_isGrounded = _raycastHit.distance <= _checkDistance;
if (!_isGrounded)
_endPosition = _raycastHit.point;
ShowIndicator();
var elapsedTime = 0f;
while (elapsedTime <= _fallTime)
{
var time = elapsedTime / _fallTime;
if (_isUsingIndicator && _indicator)
{
var fillValue = Mathf.Lerp(1f, 0f, _raycastHit.distance / _startDistance);
var fillValue = Mathf.Lerp(0f, 1f, time);
_indicator.material.SetFloat(_fillHash, fillValue);
}
transform.position = Vector3.Lerp(_startPosition, _endPosition, time);
elapsedTime += Time.deltaTime;
yield return null;
}
else if (_isGrounded && !_isAttacked)
{
_indicator.material.SetFloat(_fillHash, 1f);
HideIndicator();
if (_rigidbody)
{
_rigidbody.isKinematic = true;
}
_sphereCollider.enabled = true;
if (!string.IsNullOrEmpty(_groundCrashSfxName))
{
AudioManager.Instance.PlaySfx(_groundCrashSfxName);
}
_indicator.material.SetFloat(_fillHash, 1f);
HideIndicator();
if (!string.IsNullOrEmpty(_groundCrashSfxName))
{
AudioManager.Instance.PlaySfx(_groundCrashSfxName);
}
if (_groundCrashParticle && SpawnLocation)
if (_groundCrashParticle)
{
if (!SpawnLocation)
{
Instantiate(_groundCrashParticle, transform.position, Quaternion.identity, SpawnLocation);
Debug.LogError("파티클 위치 생성 오류");
yield break;
}
var hitCount = Physics.OverlapSphereNonAlloc(_sphereCollider.bounds.center, _sphereCollider.radius,
_hitColliders, _targetLayer, QueryTriggerInteraction.Collide);
for (var i = 0; i < hitCount; i++)
{
var hitCollider = _hitColliders[i];
var iDamageable = hitCollider.GetComponentInParent<IDamageable>();
if (iDamageable == null || !iDamageable.CanDamage()) continue;
Instantiate(_groundCrashParticle, transform.position, Quaternion.identity, SpawnLocation);
}
var hitCount = Physics.OverlapSphereNonAlloc(_sphereCollider.bounds.center, _sphereCollider.radius,
_hitColliders, _targetLayer, QueryTriggerInteraction.Collide);
for (var i = 0; i < hitCount; i++)
{
var hitCollider = _hitColliders[i];
var iDamageable = hitCollider.GetComponentInParent<IDamageable>();
if (iDamageable == null || !iDamageable.CanDamage()) continue;
iDamageable.TakeDamage(_attackDamage);
Die();
}
iDamageable.TakeDamage(_attackDamage);
_isAttacked = true;
}
if (_isAttacked)
{
Die();
yield break;
}
_sphereCollider.enabled = true;
}
private void BasicSetting()

View File

@ -68,6 +68,14 @@ PrefabInstance:
propertyPath: m_ExcludeLayers.m_Bits
value: 1024
objectReference: {fileID: 0}
- target: {fileID: 2892108968249248585, guid: bfc5c806b2fa3ba40850df302d3db0b7, type: 3}
propertyPath: m_UseGravity
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2892108968249248585, guid: bfc5c806b2fa3ba40850df302d3db0b7, type: 3}
propertyPath: m_IsKinematic
value: 1
objectReference: {fileID: 0}
- target: {fileID: 3580758810857167321, guid: bfc5c806b2fa3ba40850df302d3db0b7, type: 3}
propertyPath: m_Sprite
value:
@ -164,7 +172,6 @@ MonoBehaviour:
<CurrentHealthPoint>k__BackingField: 0
_dieSfxName:
_dieParticle: {fileID: 19826678, guid: 660dfd0ccf26cbf489a7556236949683, type: 3}
_rigidbody: {fileID: 1838738275417183443}
_sphereCollider: {fileID: 2971964863692897937}
_indicator: {fileID: 6370181286260610806}
_isUsingIndicator: 1
@ -174,15 +181,10 @@ MonoBehaviour:
_groundLayer:
serializedVersion: 2
m_Bits: 64
_checkDistance: 0.1
_fallTime: 1
_attackDamage: 1
_groundCrashSfxName:
_groundCrashParticle: {fileID: 19826678, guid: 660dfd0ccf26cbf489a7556236949683, type: 3}
--- !u!54 &1838738275417183443 stripped
Rigidbody:
m_CorrespondingSourceObject: {fileID: 2892108968249248585, guid: bfc5c806b2fa3ba40850df302d3db0b7, type: 3}
m_PrefabInstance: {fileID: 3577643095578124186}
m_PrefabAsset: {fileID: 0}
--- !u!135 &2971964863692897937 stripped
SphereCollider:
m_CorrespondingSourceObject: {fileID: 1772409705626034443, guid: bfc5c806b2fa3ba40850df302d3db0b7, type: 3}