I want to enemies move on a certain path

I am trying to create a tower defense game but the enemies are difficult to code to move on the path.
I tried using raycast from all 4 sides, if they didnt detect grass the enemy should go there. It didnt work.
Can i please have a screenshot of what code should get a good result?
I dont really know if its the way i built the map that makes the enemies move wrong, since the dirt path is at background and the grass is at game world, also its solid, and the enemy too.

3 Likes

Hi! Could you provide a link for the game where the problem is there? This is we can identify the issue. From this screenshot, it looks like you need to add a rotation block of some sorts then use forward velocity. This would most likely work because in the current setup it moves 6 x and 6y, not in a specific direction. This would cause it to move, but not in the right direction with raycasting. Instead, keep the recasting but make the enemies turn (For example 90degrees for the down raycast because the preset on Flowlab is forward = right (can be changed in object menu)) in the direction of the free space. Then put a move forward velocity of 6, for example, and watch it work!

Could I please have the link to the game?
Thanks! (Message works too apart from replying to the thread.)

2 Likes

OK i will send the link to the game.

1 Like

I modified the code a little https://flowlab.io/game/play/2202081

1 Like

It isn’t working because you’re checking for raycasts, and if it hits then nothing, if it misses then you move diagonally (6 is connected to x and y) — you would probably just want to make the enemy go forward always, and have collision blocks that when the enemy collides with (not-solid, just collideable) — the enemy turns 90 degrees.

There are quite a bit of tower defense games on Flowlab, ever since last year when they became “Flowlab trendy” — anyways, try searching “tower defense” on the games page, I’m sure something will pop up that could help you.

2 Likes

Ok, i understand it. Thanks for the help!

2 Likes

Me typing while you reply REALIZES QUESTION HAS BEEN ANSWERED

2 Likes

I’m sending a screenshot in a bit.

1 Like

Sorry I’m kinda busy with stuff, I’ll get back later if I can.

1 Like

Ok, i understood. I have a code for it which isnt really that good , but ill keep it until you have the code for a better enemy movement.

1 Like

@JR01 has a path system, try searching for it

1 Like

Ill use Sharks’s code instead but thanks for helping!

use 4 blocks : up, down , left and right.
make a parent block for enemy and use the code
:


in my game timer is set to zero.
the game is here if u need: https://flowlab.io/game/play/1849516

Thanks for the help! Ive already done that so except i used raycast that detects all 4 sides.

1 Like