I’m making a game like Vampire Survivors. The part in this case, will be the enemy. I want the enemy to follow the player at a consistent speed (the part must also account for the player changing position). I’d like to avoid CFraming as there will be many enemy at once and I know this can become laggy very quickly. Anyone have any ideas?
Is the enemy a humanoid or a part? Do you want the enemy to respect collisions? Do you want the enemy to pathfind it’s way to the player? I need more details to answer properly.
Just a singular standard basepart. Collisions and path finding are not necessary. The enemy just needs to move towards the player.
If it’s just a single part, CFraming will be not at all laggy.
I would recommend using an AlignPosition and setting one attachment to the enemy, and one to the player. More on that here: AlignPosition | Documentation - Roblox Creator Hub
Sorry not one, there could be up to 100 enemies at once. So I’m afraid it’ll become laggy quickly.
Even if it’s 100 enemies, CFraming will still perform fairly well, the only times performance will get bad is if you’re using humanoids.
I would still go for the AlignPosition route though, it’s easier to set up than doing the calculations for CFraming.
Thanks, I’ll take a look at AlignPosition. Seems like just what I need.
Alright, good luck on that, I would love to see the result.
Physics will take some performance, if it’s literally just a part that follows the player without collisions or gravity or other Newtonian laws then CFraming is gonna be the most performant way.
You could use a vectorforce and rotate the atatchment point to face the player with math
I have tried using a VectorForce before and was unsuccessful. However, I did not think of rotating the attachment part. I’ll try this too, thanks. My only problem with vector forces is the object will accelerate, and you can’t adjust MaxVelocity. However I guess that’s easily stoppable by using some simple physics equations.