Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I make enemies attack when you get close?

Asked by 4 years ago

I am making a monster fighting simulator but the enemies come at me from across the map pls help

1 answer

Log in to vote
0
Answered by 4 years ago

Hello,

Your best bet, in this case, is to use Magnitude

Magnitude will return the distance between two points. In this case, your positon and the monster's position.

Magnitude can be found using something like this:

local currentMagnitude = (zomboTorso.Position - yourHumanoidRootPart.Position).Magnitude

You could then define a minimum distance for the zombie to agro a user, and if the user is within that distance, have it chase them down.

if (currentMagnitude <= 50) then
    --Target the player!
end

A few things to bear in mind, at some point you may want to make a way to consider which player is the closest to the zombie. This will help ensure the Zombie doesn't always follow the same person!

If you need further help with this, please feel free to join us in the Discord.

Ad

Answer this question