NPC animation help

I’m making a game where i need dynamic animations that are easy to cancel on certain events, and other things

The problem I’m running into is that my moves are running server side for ease of implementation when I make NPC enemies that need to use these attacks

My options here are:
1- Handle animations server side (bad)
2- Handle animations with lots of remote communication (not preferrable)
3- Handle animations with attributes or valuebases (seems kind of bad, there’s probably a better way)
4- Just handle NPCs on the client which I’ve never done and I’m not sure how to secure them
5- Handle moves on the client initially & have ai move logic handled separately fully server sided (not preferred, but if i handle ai on the client i wont need to have ai move logic server side)

I’m wondering if theres a better option than these, and if so how i should implement it. Thanks!

1 Like

The reason I don’t want to use attributes is also each move has a set duration & its own subtrove from the character for easy cancellation. So if the move ends, but I need the animation to go longer, I need to do extra stuff to work around the animation instantly ending.

I recommend playing the animations individually for each client that needs to actually see the npc so it looks smooth for the players, and ai of npcs can be handled serverside, movement of npcs should also be handled (or mostly handled) serverside. You can use the timeposition property of animation tracks to skip keyframes, so all players can actually see the same animation at relatively the same time. This way, you can improve performance and optimize visuals.

Hi, this was originally what I had planned, but communicating to the client running the animation to do certain things (stop, speed up, etc) seemed like a pretty big issue to get done right & in the best way I can do it considering my past solutions to this have been pretty unoptimized using lots of client - server events for each animation.

You can instead use one server to client event that has arguments, for example, like a table with the following:

RemoteEvent:FireClient(animationName, humanoid, extraArgs: table)

The client can just handle that. You can still handle animations on the server, but they won’t be as smooth :frowning: thats just how it is.

Good news is that one player’s character’s animations replicate to another character which is good.

Using a setup like this, or this setup, can reduce the amount of RemoteEvents you have. You can also reuse something like this setup to reduce the amounts of RemoteEvents you use for other stuff too!

I agree that this is probably the best way to start the animations, but how do you think I should handle ending them from the client as well, I’d assume just firing the remote again, but I also feel like this might be less optimized than other possible routes, what do you think?

If they are looping animations, then you can send a stopSignal. Non looping animations will obviously stop by themselves, unless replayed.

In my game, your attack can be cancelled mid execution in which case the animation would need to be cancelled as well for a more responsive feel.

Then you can just use AnimationTrack:Stop(), or you can use Humanoid.Animator:GetPlayingAnimationTracks() and loop through them to find an animationName and stop it like that.

This is a link that might help to find current playing animations:

Yeah, but how should I tell the client to do this, I want the animations to be client side, but I feel like firing a remote for every animation event on the client would be kinda of bad for my game considering its heavily based on combat involving these moves, and parrying moves to cancel them, so that remote would be fired a lot.

I’m not too educated on how expensive this would really be but I know generally you shouldn’t over fire remotes when you don’t need to. If this isn’t that bad of a solution I will probably just do this.

Animations for the player’s character don’t need to be serverside. As long as you don’t fire an event every millisecond you should be fine.

Conclusion:
Events are not that expensive, as long as you don’t spam it. You can have anti-spam on server and client side too. Also, you can manage what client needs to play what animation where, so you can get the best performance. If handling the animations serverside is too laggy, then just use a server → client side animation handler. As long as you limit how many animations are playing for each player, or for the whole server in general, you should be absolutely fine!

1 Like

Ok, thanks. I know to handle animations client side, it was just my previous projects either handled this kind of poorly or didnt involve npc animations like this.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.