How can I make it so that my murder can detect if a player is within its range?

Hello there!

I’m also done making a simple killer script for a survival game, the only issue is that I don’t know how I can make it so the killer will attack anyone within a 3,3,3 radius and so on. How can I do that?

I was opting on using Region3 or creating hitboxes, heck, maybe even raycasting. Anyway, how can I do that?

1 Like

If you are focused on a attacked based around the player (rather than where they click), you would use Magnitude (The distance from one point to another. Roblox already does this for you with .Magnitude, which is usable within Vector3 and Vector2 related DataTypes. But you need to calulate the different between one point from other by subtracting point 0 with point 1, like this:

local p0 = Vector3.new(0, 0, 0); -- point 0
local p1 =  Vector3.new(10, 10, 10); -- point 1

local distance = (p0 - p1).Magnitude -- returns a number
-- p0 - p1 is the area we are looking when calulating the distance

you can then check if the targets are within a certain range of this, then execute whatever code.

However if you are focused on where the Player is clicking, thats when you use Raycasts, in order to use them you need a Origin, and a Direction to fire in.
For the position, you can just use the Player’s current Position, or the weapon position. For the Direction, you need to convert using .Unit, its essentially the same process as .Magnitude, however instead of a distance, its a position of where you want the attack to be, either being in front of you, or where the player is pointng to. But when performing the raycast, you need to mutiply the direction to apply any range to it.


Outdated, and obsolete.

1 Like