Tower Defense Game Enemy Movement

Yo,
I’m trying to make Enemy Movement in my Tower Defense game more similar to the one from TDS. Right now the Enemies are moving in a straight line and one behind each other. I want them to be placed more random and not really on the same X-Z Axis (Depends on the Rotation of them). How can I even achieve that?

Screenshot from TDS:
image
As you can see on this ss the zombies aren’t walking in the same X-Z Axis they are more to the left or to the right.

Screenshot from My Game:
image
As you can see here. The Enemies are walking in a straight line in the middle of the path. Not being more to the left nor right

So how can I achieve making smth like this?
btw i’m using Client-Side rendering to make it more optimized

2 Likes

Why don’t you give them a random offset when the spawn and the same offset to the goal. Just make sure the offset isn’t too much or the NPC will go off the track.

1 Like

When your making them walk add a slight offset, like:
Don’t get confused by this but its actually really simple!

2*(Vector3.new(math.random(),0,math.random())-Vector3.one*0.5)*Intensity
2 Likes

I’ve tried doing that before but it didn’t really work as it should

1 Like

I tried using that before but the problem is that whenever they change the way they are looking I would need to change the offset to from x to z etc.

1 Like

Use CFrames to offset the entity’s position. What you are doing right now is just incrementing/decrementing the Vector3 of the entities, which will lead to desynchronization by a few studs.

I presume you are sending the CFrame of the entity to move them in the client (and I highly recommend to offset on the client), so you could multiply the CFrame by the randomized offset, sorta like this:

local offset = CFrame.new(randomizednumber, 0, 0) -- offset the CFrame on the X axis.
FinalCFrame = SentCFrame * offset
1 Like