W
W
WasTabon2022-03-10 17:05:26
Unity
WasTabon, 2022-03-10 17:05:26

How to let Raycast around the area?

Even MB is not purely a beam, but something like a computer. of view so that the 2d sprite can use it to check whether other objects are in the field of view (I don’t want to use the trigger because it will see through the walls

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
Nekit Medvedev, 2022-03-11
@WasTabon

Usually many beams are used for these purposes, or one beam is rotated within the zone, in any case, this is how the field of view in the game is usually described, the option described in the comment (with a trigger) is also quite good, it will reduce the number of Raycast calls to the number of objects in the trigger, however, if too many objects fall into the trigger, there will be an overflow of Raycasts, many of which will be resent. In addition, only the castles climb into the head ...

W
WasTabon, 2022-03-12
@WasTabon

rayShootPos = playerObject.transform.position - transform.position;
hitShoot = Physics2D.Raycast(transform.position, rayShootPos, shootDistance);
if (hitShoot.collider != null)
        {
            Debug.Log(hitShoot.collider.gameObject.name);
            if (hitShoot.collider.gameObject.name == "Player")
            {
                Debug.Log("Player Dead!");
                needToShoot = true;
            }
            else
            {
                needToShoot = false;
            }
        }
        else
        {
            needToShoot = false;
        }

And if needToShoot = true, then it will shoot. Gavnokod, but as it is so it is

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question