Best way to create enemy NPCs?

to preface: i’m sorry for my poor behavior that lead to my posts being wiped. i’ve changed and will not repeat

so i’ve been studying my friend’s code lately and saw that he scripted a simple zombie. you might have seen a post of his before asking the same question, but how do games make NPCs smoothly turn without constantly updating their position?

and yes, we did do the “set ownership to nil” for every NPC. the footage is laggy since OBS butchers my cpu.

how they work in our game: (jittery)

how they work in other games:

here’s some code samples from the zombie script:




as you can tell it’s held together by glue and duck tape. my friend requested me not to just copy his scripts into text.

i’m jealous games from 10 years ago have smoother npcs, play dungeon delver and you’ll see what i mean

1 Like

It’s pretty easy, you should definitely utilize a module, and get some OOP systems going to create an NPC class. Give your NPC states, like “Attacking” and “Wandering”, this accounts for more realistic NPCs.

And lastly, use :Move(). It moves a humanoid in a direction, instead of :MoveTo(), which you have to call frequently, this might lead to some choppy behavior.

The NPCs in the video are probably calling :Move() at decent intervals, from observation I’d say 0.3 seconds. And you really shouldn’t have to call it more than that. Especially if you’re going to have A LOT of NPCs.

The last thing to do is implement path-finding, but that’s a whole other problem not relevant to this topic.

1 Like

thanks for the advice, moveto: kind of sucks
could you give some code samples or like elaborate a little more, maybe link some docs, sorry i’m in a bit of a rush rn