I am moving a single part toward the player on the server in a loop that updates the CFrame on that part every .25 seconds. This part will represent a mob chasing the player and the visual for that mob will be handled on the client.
I would like to get some advice and a review on my code to move that part.
Currently, what I am doing is 2 CFrame operations. The first operation rotates the part to face the player, the second operation move the part toward the player based on its MoveSpeed and LookVector.
here is the code running on the server:
local distanceToMove = mob.MobData.MoveSpeed * updateTime
mob.ServerPart.CFrame = mob.ServerPart.CFrame + (mob.ServerPart.CFrame.LookVector * distanceToMove)
mob.ServerPart.CFrame = CFrame.new(mob.ServerPart.Position, targetHRP.Position)
I cant help but think that if I could get this into a single operation, it would simplify and speed the loop up. This optimization might help be because this loops is running fairly quickly and we are trying to get as many mobs moving as possible.
Currently we are able to run something like 2k of them parts moving around without much noticeable effect on the server, but this is the only system running now, so optimizations are key.
Any help or advice is greatly appreciated!