hi, im trying to make a tower defense game and im making the enemies
now ive come across a reply which is this:
and so i would basically need help with this since i cannot reply to a topic that old
so, as he said he’s doing client sided rendering, so on the server side enemies are just tables with the position and stuff and that position gets sent from the server to the client and on the client is where the actual enemy model is made
what i dont understand is moving the position on the server side, he said in that topic that he’s using CFrame:ToWorldSpace to move enemies to the next node, which i might be misunderstanding because on the server enemies are just tables, and tables dont have cframes
so yea just basically trying to understand what hes doing on the server to make the enemies move to the next node
When I mention “position” in the table, it’s actually a CFrame. You can store a lot in tables, including CFrames. A CFrame in the table and a CFrame of a part are still both CFrames.
To move the enemies on the server I run a Heartbeat event, which runs 30 times a second, and in the heartbeat I make the enemy move forward.
Using ToWorldSpace we can make the enemy move in the direction its looking no matter what, so it will always move forward and not sideways or backwards. We give ToWorldSpace another CFrame, which is how far it moves.
When I set the position, I use the second argument of CFrame.new which is like the direction its looking. I give it the next nodes position so it’ll face towards the next node. Say all your nodes are number ordered, we spawn it at 1 and make it face towards 2.
Lets also store the current node so we know where we are. We can check if we’re near the next node by doing a magnitude check every time we move with the next node. If we’re close enough then we’ll increase our node, and make our enemy face the next node.
This code would move the enemy by 1 stud 30 times a second, going through the nodes. This code is untested so it might not actually run, but its a super simple version of what you would want to do.
Its really up to you how you organize stats, I made a single enemy module for all the stats but its mostly preference, I prefer not having 50 scripts open to edit multiple enemies.
and so here what i assume is that this a serverscript and that EnemyInfo is kind of like just a general info for all enemies, because things like the health and such are defined by the modulescript that you said all your enemies are in
ive noticed that youve managed to make it so that the enemies are just strings
so im not sure how to describe this, but how did you achieve gettings the specific enemy like walker, getting its info from the module script and spawning it