How can I make NPC's attack players within its range?

Hello there!

I’m currently working on a satire survival game and I’m currently wondering how I can make NPC’s attack players within its range? Would I use Magnitude, hitboxes, etc for it?

1 Like

Maths is normally the best way to do stuff, check out docs for Vector3 Magnitude

1 Like

Wouldn’t that be able to also attack players indirectly? For example, if two players are within a killer’s range and the second player is behind the killer, wouldn’t the player be damaged as well?

1 Like

You could incorporate a raycast when you’ve got the vector to check for any obstacles

1 Like

yes, it would damage players behind the killer.

i recommend using a dot product if you intend for the killer to have a “field of view”

this video explains it pretty well:

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.