Tower Defense - Animating help!

i want to know the best/most performant way of moving a mob through waypoints

I watched the gnomecode video about it but then i searched more about it and apparently using humanoids is bad? im not sure how bad it truly is but i saw that tweenservice is better which i tried but it ended up being weird

The expected behavior is it would be like MoveTo except it just ended up looking like it was teleporting with tweenservice

and same question for towers how would you rotate them to be facing the enemy on the client

1 Like

I’m not the best to ask about NPC movement.

For the towers questions however, you can rotate it by setting its CFrame:

Tower.CFrame = CFrame.new(Position, TargetPosition)

If you want it to smoothly rotate to look at the target you could look at tweening the CFrame or using AlignOrientation/various joints/motors to achieve similar results, although if you wish to use motors/joints built-in smoothing methods then I believe you’ll need to work in angles which takes a bit more math.

i get that but im talking about it having to match with the server

Is there a reason why it has to be run on the client? This code should function client-side so long as you’re fine with no replication to other clients/server. If you want replication you could experiment with setting the network owner of the turret to the client and modifying the CFrames that way?

It’s depends on what you’re trying to achieve.

basically this post except the solution doesn’t really help for how to do it

Ah I think I understand now. Assuming this is single-player and you intend on running the physics on the client:

TweenService was a good idea. You can remove the humanoid entirely and use an AnimationController to make the walking animation. Tween duration needs to be a function of the distance between the two points: Duration = Distance / WalkSpeed. For each straight length of path, you’ll need your own tween, with potentially other tweens at each ‘corner’ to handle rotation unless you want your NPCs drifting through each corner. Utilise the .Completed event of each tween to know when to activate the next one. You can do all of this in a LocalScript on the client.

If progress and such is being saved and used in a leaderboard-type situation then you can update the server script with progress via remotes. If you’re concerned about exploiters, it’s a potential weakness of this system, but equally most exploits/exploiters won’t be advanced enough to abuse it so long as you’re smart with the type of information you’re sending over as well as sanity checking on the server to make sure. My point about network ownership may still benefit you as well. If you create your npcs on the server, set their network ownership to the client, then have the client tween the npc, then that movement should be replicated to the server. In that case then you’ll be able to handle the turret logic server-side or client-side (whichever you decide).

If you still wish to use humanoids, make sure you’re disabling as many unnecessary states as possible to free up some of the internal processing that the Humanoid’s controller is doing in the background.

Here’s some advice about Humanoid optimisation: How to Optimize Humanoids