(SOLVED)Help with roaming enemy path

I am trying to make a path for an enemy to move on while they don’t notice the player by using a sprite that moves after a random amount of time while the enemy is colliding with it, but no matter what I do, it either A: doesn’t move after reaching the second point in its path, or B: the sprite moves to 0, 0 and the enemy can’t reach it. the positions the sprite can move to are specified in 2 object array variables, 1 for X and 1 for Y, and 3 positions are specified in each of them. the code I have right now results in outcome A.

1 Like

I think the issue is that you have a less than 3 and an inverted is less than 3 which is basically greater than 3. So, you have nothing for equals 3.

So, once it’s 3 it doesn’t trigger either event. When it’s 3 it tries to get the value from index 3 of the array which I’m guessing doesn’t exist. When an index doesn’t exist, the default value of 0 is returned.

If you change the 2nd event from inverted less than to uninverted equals 3 (or whatever your last node is) then it should work. Although, it’s best to not try to read indexes that don’t exist bc GD will create them and that can cause unexpected results.

This would work. This used an array that had 4 indexes or children. It didn’t use index 0.

This is how I recreated your process. I used mod() because it wraps the value. So, you don’t need to check it. This array starts at zero.

Personally, I would use a different technique. I would add node objects with an ID variable and then target the nodes using an array of ID numbers. You would pick the target node by checking if the node ID variable equals the enemy TargetID value. I might create an example if I have the time.

If you have multiple enemy or linked node objects then some parts might need to use for each object.

3 Likes

Heres my technique. I believe it’s bug free but needs more testing.

I used 2 objects. An enemy and a node.

My scene.

The enemy objects have an array of IDs and a path index.

The nodes are sequentially numbered. It doesn’t matter if they start at 0 or 1 because the objects follow the IDs in the enemy array. They just need to be unique.

My events

1 Like

fixed it with your advice on changing the inversion, thanks for the help!

2 Likes