How can i make an enemy

im making a 3d platformer game and i want to make an enemy that will attack you i have the model and i know how to animate it but i dont know how to rig it or script it
i want it to kill the player when they touch it but it only chases the player once they enter the enemy’s patrol area sorry if this is to much to ask but how would i script and rig it

1 Like

just to let you know the thing im making an enemy is a mesh and its also only one mesh so theres no joints

If you want to rig an enemy, I suggest you look into rig edit lite, which allows you to connect bodyparts

i tried using that but my enemy model is 1 mesh so it doesnt work

ohh, well then I don’t think you can. It won’t work unless you have full body parts

For the rigging:
You can group a Humanoid with your mesh, then make your mesh as the PrimaryPart of the model, and toggle off the RequiresNeck property, since your rig doesn’t need a neck joint. Make sure that the mesh is unanchored.

For the scripting:
What you should do is have a while loop (with the condition set to something checking if the enemy is still alive, so the loop stops if the enemy dies), and the loop is responsible for setting the movement of the enemy. Have the loop wait something like 0.1 to 1 seconds between each loop (so that you’re not wasting resources looping a huge amount, or crashing the game).

Have the loop’s contents be to set the Humanoid’s WalkToPart property to be the PrimaryPart of the character closest to it, and within distance.

You can figure out which character is closest by making two variables, ClosestCharacter and ClosestDistance. Default ClosestDistance to the range of your enemy, then loop through every player in the game, and if they have a character, and that character has a primary part, then check its distance (Enemy.PrimaryPart.Poisition-Character.PrimaryPart.Position).magnitude is less than ClosestDistance. If it is, then set ClosestDistance to the new shortest distance, and set ClosestCharacter to be the character that the loop was currently on. After the loop has checked every character, then the value of ClosestCharacter should either be nil, or it will be the closest character that is within range.

but u ant animate it then

toooooshortttttttttttttttttt

Why couldn’t you animate it? I’m not explaining to him how to animate it, just explaining how to get it to move like he asked.

if its one mesh, how would u be able to animate its different body parts

For the attacking part I recommend this tutorial:

And for the damaging since in the tutorial it has a sword. Just damage the player directly.

Meshes can be exported with bones, and you can use mesh deformation to animate them if you want.

You can, not sure if the person is doing that though

the problem is that the mesh is just one block like a slime so i cant rly add joints i just want the whole thing to move towards the player and it would animate like pet simulator pets it just wobbles back and forth

watch a tutorial on how to Rig a Custom Model on roblox studio

1 Like