I create 1-3 Monsters in the ObjectGroup Monster on random Positions.
i then create a field of “noSpawn” around the enmies that is currently visible but will be hidden when everything works.
i create a random starting point for the player and 2-4 extra spawnpoints for the player.
the player can choose the spawn possition and press “in position”
then “start Battle” or “Replace” (no function yet) pop up and after pressing “start Battle” the enemy gets their movement points as MovementLeft also i create a small red dot as marker for the starting position of each monster.
Whats not working
The battle begun and only 1 of multiple Enemies start moving in the direction of the player.
The Movement-Left variable gets reduced to -138 after the first movement instead 1 by 1 until 0
When Monsters begin in a position 1 row above or below the player they start cutting edges instead snapping to grid as they normaly do.
HP Bars sometimes stick to the wrong Monster and it looks like its dissapeared (this happens very rarely)
Monsters that are in the way of another monsters dont move at all but use up their MovementLeft
What is the actual result
You can test it here. but since a lot happens random you need multiple attempts to see diffrent issues.
Why doing it like this
I am trying to get the Enemy movement done for a few days now. and i found no way to make the movement like i wanted it to be. but this was the closest way. if there are better ways to achieve this i am happy to hear suggestions and ideas ( best with a screenshot of conditions/events)
If you want grid based movement, it might be easier to use the Linked Objects Tools Extension. It uses object based movements. You create usually a grid of tiles and use them for the movement. It takes more to setup but once setup the movement is easier. The object moves from tile to tile using the shortest path.
If not, the issue seems to be the last repeat. You’re using a repeat number of times. IDK if you need a for each instance instead or a condition to pick only certain objects. It’s currently going to apply to all instances.
Also, be careful when using wait actions. I prefer timers. But, if you use a wait make sure there’s either a trigger once or if you’re using a boolean, make sure the boolean gets changed before the wait. Otherwise, you might get a lot of wait events stacked up or queued.
i already tried the movement from:
Tactical games: selection and movement of units on a hexagonal grid (open the project online)
but i was unable to get any movment for the enemy.
i use something like this already for my player since i can use a condition like Cursor on object but i found no solution for the enemy.
It’s picking the monsters linked to the health bar. If there are multiple health bars then the condition is likely using the oldest created health bar an the object on the right and then picking the monsters linked to the health bar.
The for each monster is a subevent of it. So, the objects picked by it will be the only objects in the picklist.
The repeat monster event is also probably using the oldest object.
.
You probably need to start with a for each instance event instead of the repeat event.
Maybe
If monster turns left variable > 0
…for each monster
… … Among health bars linked to monster
Monsters move now 1 time, a 2nd time and stop (nearly) they then move with 1-5px per frame towards the player (i updated the shared game, guess its easier to see instead of trying to descibe)
I’m not sure I understand. Are the enemies limited to a certain number of moves per turn?
You can set the pathfinder to not use diagonal movement. Although, I don’t like that bc people move diagonally. When set, the object moves all the way in 1 direction first and then does the other direction. I would prefer if it did diagonal movement but only when it fits the grid. That’s where the other pathfinder helps.
Now, if the object can only move a certain distance then you can do a move action, calculate the distance and then move either to that distance or to the destination if the distance is within range. It evolves adding up the nodes.
As is, it might help if the object is done moving that you move the object to its current position instead of disabling the behavior. That way it doesn’t have a leftover path.
It’s difficult to try to align an object to a grid while using the pathfinder. It’s best to have the path follow the grid. You can plan the path or calculate the moves.
You could d also use the pathfinder to find a route and then do the moves using a tween. I think I post about this before. You use the direction to the next node for the angle.
Is the pathfinder’s grid set to the same size as your snap size? That would help.
Enemy has Moves from the Object Flem which is part of the Object Group Monster and gets 2 Moves.
I deactivated diagonal movement.
for movement i use pathfinding behavior with target playerX & playerY.
when the enemy is at its turn i set the speed 128 (my grid size and all objects are at size too, collisionboxes as well) for exactly 1 second.
when the second is over i set the speed to 0, when speed is 0 i substract 1 movement and start over until movement is 0. in this case 2 times.
but after the movement is done, movement reached zero, the enemies still drift towards the player. like there is a force shoving them with speed 2-5 per towards their target.
i will check your links, thanks so far for your help!
My solution to start the movement and turn off the drifting with 6.66666 px per frame after my speed settings was just to turn on the behaviour of pathfinding at the start and off when the movement is done.
Looks like this now: