TIL 0417 최종 프로젝트 - 18 / Ball 폭발 대상 / 롱스톤 현상

강성원·2024년 5월 12일
0

TIL 오늘 배운 것

목록 보기
64/69

수정한 내용

Ball 폭발 대상

Ball 터질 때 탄막도 같이 날려버려서 Entity 컴포넌트 가진 애들만 날려주도록 로직 수정

private void Explosion()
{
    float damage = Context.Entity.Stat.damage;

    RaycastHit[] hits = Physics.SphereCastAll(Context.Entity.transform.position, 10, Vector3.up, 0f);

    foreach (RaycastHit hit in hits) 
    {           
        if (hit.transform.gameObject.TryGetComponent(out Entity entity))
        {
            Rigidbody rigidbody = entity.transform.GetComponent<Rigidbody>();

            if (rigidbody != null)
            {
                Vector3 other = hit.transform.position;
                Vector3 pushDirection = (other - _entityTransform.position).normalized;

                rigidbody.AddForce(pushDirection * 20, ForceMode.Impulse);
                rigidbody.AddForce(Vector3.up * 20, ForceMode.Impulse);
            }

            if(entity.IsAlive) 
                entity.GetDamaged(damage);
        }
        ,,,생략,,,
    }
   ,,,생략,,,
}

SphereCastAll을 해서 감지된 대상이 Entity컴포넌트를 가지고 있으면 힘을 가한다.

롱스톤 현상

  • 문제
    기존에는 랜덤으로 섞인 스폰 포인트 배열을 가지고 한 스테이지 만큼 소환하고 ->
    다음 스테이지에서 스폰 포인트 배열을 섞어주는 방식이었음.

    팀원이 만든 몹 스폰방식은 스폰 포인트를 하나씩 불러오는 것임.

    두 방식이 안맞다 보니 구체 몬스터가 한 스폰포인트에 계속 스폰되어 똑바로 서있는 롱스톤 처럼 되어버렸다.

  • 해결
    스폰 포인트를 큐로 바꾸고 스폰 포인트를 하나씩 꺼내 쓰는 방식으로 변경

public class SpawnManager
{
    ,,,생략,,,
    public Queue<Vector3> _groundSpawnPoints = new Queue<Vector3>(); // 탐지 후 찾아낸 스폰 포인트

    public SpawnManager()
    {,,,생략,,,}


    private Vector3 GetSpawnPoint()
    {
        Vector3 spawnPoint = _groundSpawnPoints.Dequeue();
        _groundSpawnPoints.Enqueue(spawnPoint);

        if(Physics.CheckSphere(new Vector3(spawnPoint.x, 1f, spawnPoint.z), 1f, LayerMask.GetMask("Target")))
        {
            spawnPoint.x = spawnPoint.x + UnityEngine.Random.Range((int)-cellRadius, (int)cellRadius + 1);
            spawnPoint.z = spawnPoint.z + UnityEngine.Random.Range((int)-cellRadius, (int)cellRadius + 1);
        }

        return spawnPoint;
    }

공중 유닛 부동 문제

공중유닛 움직이지 않는 문제 => mass가 25였음 ㅎㅎ..

profile
개발은삼순이발

0개의 댓글