티스토리 뷰

https://www.youtube.com/watch?v=711KSrbTIt4 

https://www.youtube.com/watch?v=ddakS7BgHRI 

https://www.youtube.com/watch?v=EZnIXz6GLlE 

https://www.youtube.com/watch?v=Qxs3GrhcZI8 

 

#enemy의 기준으로 Random.insideUnitCircle.normalized 사용했으나 너무 범위가 넓어 위와 같은 모습이 나오지 않았다

#내각을 정해주고 그 위치에서 흩뿌려주게 만들어야했다

using UnityEngine;

public class BossBulletPattern : MonoBehaviour
{
    public GameObject bulletPrefab; // 총알 프리팹
    public int numBullets = 5; // 총알 개수
    public float spreadAngle = 30f; // 총알이 퍼지는 각도 범위
    public float bulletSpeed = 5f; // 총알 속도
    public float bulletLifetime = 3f; // 총알 지속 시간

    private Vector2 pointL;
    private Vector2 pointR;
    private void Start()
    {
        //내각
        var pivot = 90; 
        var sight = 45;

        var cos = Mathf.Cos((pivot + sight) * Mathf.Deg2Rad);
        var sin=Mathf.Sin((pivot+sight)*Mathf.Deg2Rad);
        this.pointL=new Vector3(cos,0,sin);

        var cos2 = Mathf.Cos((pivot - sight) * Mathf.Deg2Rad);
        var sin2 = Mathf.Sin((pivot - sight) * Mathf.Deg2Rad);
        this.pointR = new Vector3(cos2, 0, sin2);

        //0f 후 2f간격으로 "Fire"호출
        InvokeRepeating("Fire", 0f, 2f); 
    }

    private void Fire()
    {
        Debug.LogFormat("<color=red>{0}, {1}</color>",this.pointL,this.pointR); //-0.71, 0.71
        // 총알을 여러 방향으로 뿌림
        for (int i = 0; i < numBullets; i++)
        {
            // 랜덤한 방향과 속도로 총알을 발사
            //insideUnitCircle->random point inside a circle with radius 1 (원호 안에서 랜덤한 값 반환)
            //Vector2 direction = Random.insideUnitCircle.normalized; //너무 범위가 넓음, 내각을 정해줄 필요가 있음
            Vector2 direction=this.pointR-this.pointL; //방향
            float angle = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg;
            //float angle = Mathf.Atan2(direction.y, direction.x)/2 * Mathf.Rad2Deg;

            angle += Random.Range(-spreadAngle, spreadAngle);
            direction = Quaternion.AngleAxis(angle, Vector3.forward) * Vector3.right;
            GameObject bullet = Instantiate(bulletPrefab, transform.position, Quaternion.identity);
            bullet.GetComponent<Rigidbody2D>().velocity = direction * bulletSpeed;

            // 일정 시간이 지나면 총알을 파괴
            Destroy(bullet, bulletLifetime);
        }
    }

    
}
#앞으로만 나간다 ㅎㅎ 머리 위로 나가게 내각을 수정해야겠다

 

using UnityEngine;

public class BossBulletPattern : MonoBehaviour
{
    public GameObject bulletPrefab; // 총알 프리팹
    public int numBullets = 5; // 총알 개수
    public float spreadAngle = 30f; // 총알이 퍼지는 각도 범위
    public float bulletSpeed = 5f; // 총알 속도
    public float bulletLifetime = 3f; // 총알 지속 시간

    public Vector2 pointL;
    public Vector2 pointR;
    private void Start()
    {
        //내각
        var pivot = 180; 
        var sight = 90;

        var cos = Mathf.Cos((pivot + sight) * Mathf.Deg2Rad);
        var sin=Mathf.Sin((pivot+sight)*Mathf.Deg2Rad);
        //this.pointL=new Vector3(cos,0,sin);
        this.pointL=new Vector2(cos,sin);

        var cos2 = Mathf.Cos((pivot - sight) * Mathf.Deg2Rad);
        var sin2 = Mathf.Sin((pivot - sight) * Mathf.Deg2Rad);
        //this.pointR = new Vector3(cos2,0,sin2);
        this.pointR=new Vector2(cos2,sin2);

        //0f 후 2f간격으로 "Fire"호출
        InvokeRepeating("Fire", 0f, 2f); 
    }

    private void Fire()
    {
        //Debug.LogFormat("<color=red>{0}, {1}</color>",this.pointL,this.pointR); //-0.71, 0.71
        // 총알을 여러 방향으로 뿌림
        for (int i = 0; i < numBullets; i++)
        {
            // 랜덤한 방향과 속도로 총알을 발사
            //insideUnitCircle->random point inside a circle with radius 1 (원호 안에서 랜덤한 값 반환)
            //Vector2 direction = Random.insideUnitCircle.normalized; //너무 범위가 넓음, 내각을 정해줄 필요가 있음
            Vector2 direction=this.pointR-this.pointL; //방향
            float angle = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg;
            //float angle = Mathf.Atan2(direction.y, direction.x)/2 * Mathf.Rad2Deg;

            angle += Random.Range(-spreadAngle, spreadAngle);
            direction = Quaternion.AngleAxis(angle, Vector3.forward) * Vector3.right;
            GameObject bullet = Instantiate(bulletPrefab, transform.position, Quaternion.identity);
            bullet.GetComponent<Rigidbody2D>().velocity = direction * bulletSpeed;

            // 일정 시간이 지나면 총알을 파괴
            Destroy(bullet, bulletLifetime);
        }
    }

    
}

 

#머리위에 포물선을 그리는건 성공했다 

 

#bullet의 lifetime이 지나면 사라지며 그 위치에범위공격 효과를 구현하고싶다

 

공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/07   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
글 보관함