Enemy AI Movement on contacting player Plus More

So I’ve got 3 things in which I’m looking for support

  1. I’ve got some basic combat with a mob

Keep in mind the mob does not do damage right now. In the finished product, he will. So the problem with this video is that when he Mob gets to the player he just starts pushing him. I need the Mob to Stop and Attack not just push the guy while dealing with damage. If anything the guy should be able to push the mob a little. End Result: When mob gets within 3 Studs of the character he stops until the character is more than 3 Studs away in which it starts following him again.

So I’ve got an Idle animation for when the player isn’t moving. It works fine when equipping and unequipping an object. The only problem is when the player is running it keeps playing this idle animation.

  1. When the Mob is within 5 Blocks of the Player I’d like it to start shooting a beam of light at the player in bursts such as it shoots a beam to the players torso for 2 seconds then waits 5 seconds or a cooldown value before doing it again. And when taking damage it will have a chance of waiting 7 or 10 seconds.

Thanks for taking the time to read threw this. If you know of a step threw on how I would go about adding/fixing these features that’d be much appreciated. If not any links to wikis which you think might help would be helpful as well.
-Kind Regards
ZoomCode!

1 Like

May we see the scripts being used for this.

For counting the five blocks you can use magnitude. Vector3 | Documentation - Roblox Creator Hub. You could produce something like this out of the api:

if rootPart.Magnitude - enemyPart.Magnitude >= 5 then
-- code
end

For the stopping when on the player you can use the Touched and TouchEnded event or use magnitude again. enemyHumanoid.Touched:Connect(function() enemyHumanoid.TouchEnded:Connect(function()
or
if rootPart.Magnitude - enemyPart.Magnitude <= 1 then end

1 Like

I’ll give this a go Thank you!