Trying to set waypoints with array but it doesnt update after reaching waypoint

im trying to have a monster enemy follow a path using the pathfinding behavior and coordinates i set in an X array and a Y array, refering to each set of coordinates as a waypoint

so the monster has two arrays; waypoints X and waypoints Y. each value in one array correspondes to the next, if the values in waypoints X are [100, 200] and the values in waypointsY are [350, 16] the first waypoint would be X:100,Y:350 and the second waypoint would be X:200,Y:16

im using a variable called “waypointIndex” to keep track of what set of coordinates we are currently on. so if waypointIndex is 0 it should look at the 0 value of each array, if set to 1 look at the 1 value of each array, so on so forth

to figure out which array value the game should be looking at im using
“monsters.waypointsX[Variable(monsters.waypointIndex)]”
(change the X to a Y to look at the Y array)

so when the scene starts the monster should move to the first waypoints, the 0 value of each array, once its within 5 pixels of that point, add one to the waypointIndex which should trigger it to move to the next set of coordinates

currently, the monster goes to the first waypoint, waypointIndex does update, but it doesn’t change where the coordinates are set to, so it doesnt move to the second waypoint, and im not sure why not.

code

current settings on monster instance

The variable system was updated awhile ago. Variable() and the VariableString() expressions are no longer needed.

That being said, the old syntax for an object variable is

Object.Variable(variableName)

Your event is trying to read a scene variable. If that variable doesn’t exist, it will always return zero.

Variable(Object.variableName)

If you remove the Variable() expression then it should work.

Alternate, you could use the reached destination action.

I also used mod() and the child count expression to simplify it further.

If the destination or the obstacles don’t change then you don’t need to trigger the move action on every frame. If they do, then, yes, you’ll need to update more often.

1 Like

that did seem to fix it, however another problem i have is that when i use the object has reached destination condition, it doesn’t add 1 to waypointIndex, ive worked around it by having it check if its within 5 pixels of the coordinates, but idk why it doesn’t just work with the destination event

Can you post a screenshot of the events? My version works with my example.

they haven’t really changed that much, but here you go, i also posted my behavior setting for the object if that helps

btw i ended up not using the mod simplification you suggested because im not sure wether or not that will interfere with some other stuff im doing yet.

Does this version work?

If you’re talking about the events i just posted, no

Are there multiple monsters? What doesn’t work in those events?

You probably need to move the reached destination event to it’s own line. Currently, it’s a subevent of [inverted] reached destination. It can’t be true and false at the same time.

Ive tried it with the inverted reaced destination event removed as well, still didn’t work. Yes there will be multiple monsters in the finished product, currently im just working with one though.

When i use the reached destination event, the monster goes to the first waypoint, but when it stops moving, waypointIndex is not updated.

I don’t have the time to test it or compare it to mine but askng as the variables are the correct values and the reached destination is on its ownine then it should work.

ive tried it like this

and like this

in both instances waypointIndex doesn’t get 1 added to it, but it works fine if i check if the monsters position is within 5-10 pixels of the coordinates, so im not sure whats happening.

im using 48x48 sprite if that makes any difference

okay, i double checked, and in the second example in my last reply, waypointIndex DOES update and so do the waypoint coordinates, but the monster doesn’t move towards the second waypoint for some reason

i also tried it this way using your suggestion to simplify and that also doesn’t update waypoint index

Edit, nevermind, i realized i was using X where i should’ve put waypointsX for my code. this does work, thank you

1 Like

@Keith_1357 so I’ve been using the code you provided, and it is working fairly well, but occasionally the monsters still get stuck, but it seems to be completley random when it happens, im not sure what’s causing it

when they get stuck, every instance of monsters in the scene gets stuck all at once, and i think its tied to the position of my player in relation to the monster somehow

heres all of my events, im not sure what to do


Most of it seems right.

I’m unsure about the trigger once inside the last for each instance. Trigger once works on an object level not instance. It’s best not to use them inside a loop with instances. Once 1 object triggers it, it might prevent the other instances from triggering.

If you need to make sure something doesn’t trigger again, you could use an object boolean instead or some other conditions. I don’t have a firm grasp of what agro does and what causes it to be changed. So, I can’t make any other suggestions…

Tey removing the trigger once and see what happens. Maybe, the agro variable is enough.

i tried that it didn’t change anything.

aggro controls wether the monster is chasing the player or patrolling, the waypoints system is to lay out its patrol route. each monster has an invisible vision cone that when the player collides with, it changes the aggro variable to true and the monster becomes aggressive to the player and chases them by using the pathfing behavior to follow them

I can’t really see anything. You’ll just have to keep debugging it. Check the values of the variables and maybe add a subevent of the pathfinder move events to check if the path was found.

i’m not sure why, but i think this fixed it

its hard to debug, cuz its practically random, but i haven’t been able to trigger it since i changed this so i’m hopping this worked

thanks again for all your help, sorry for bugging you

1 Like

@Keith_1357 …I think you deserve a box of chocolates!

1 Like