Support Forum

2D (SideScoller) Pointgraph - Seeker chooses point on wrong y level

Hi there, I’m currently developing a 2D sidescroller using point graphs. The waypoints are connected through nodeLinks.

When enemies sense the player, they will select the player as target and move to the player position. This works fine, except when the closest waypoint is not on the same y axis as the player. In this scenario the enemy will find the waypoint above or below the player and move there instead.

Scenario 1: This works because the player is close to a waypoint on the same y axis

Scenario 2: This is where the problem occurs. The enemy has the player set as target, but tries to get to the closest waypoint, which is above.

The issue is fixed if I place an extra waypoint below the orange waypoint on the upper y axis, at the same level as the player (sorry I can only add 2 images as new user). However this is not an ideal solution.

Is there a way to adjust the seeker so only the closest waypoint on the x axis is considered?

Thanks for any help :slight_smile:

Wouldn’t you then get the exact same issue, only when moving upwards/downwards instead?

Which movement script are you using?

Hey, thanks for helping me look into this. I am using a custom movement script with NodeLink1 connections.

The upwards/downwards movement is a teleport between the connected (orange) points. The way it works:

  • destination is a waypoint on a different y axis (in this example any of the points above)
  • enemy gets close enough to the orange point (on y=0) and triggers the OnTriggerEnter2D
  • waypoint checks if the next point in the path is close to the connected (orange) waypoint directly above
  • if it is it starts the animation sequence for the enemy and teleports them up
  • enemy moves along the x axis to the next point in the path

Wouldn’t you then get the exact same issue, only when moving upwards/downwards instead?

Yeah, I can see now how that would only create a different problem. I guess I could just add the extra waypoints on the y=0 level to make sure that those are the closest ones. A bit of extra work, but I’ve already tested it and it solves the issue. If you have a suggestion on something else that might work, I’d be happy to give it a try.

Hi

If you have your own movement script you might know where the next node in the agent’s path is. In that case, you could send all the enemies towards that point instead of towards the player’s own position. That will allow them to always get the right now. This is assuming the player cannot stay between two nodes.

Otherwise, I think the easiest solution is to just make the graph a bit denser and add more points.

You can also subclass the PathNNConstraint class and prevent it from choosing any node which has a large Y coordinate difference. This can then be sent to the path by setting the path.nnConstraint field.

Hi Aron,

thanks for the suggestions, I appreciate it! The player can currently stay between the nodes and some of the connections with a large Y difference are used to connect certain parts of the game (eg the outside door of a room being on y=0 and the inside door of the room being on y=15. The enemy then teleports when they access the door).

I think that only leaves adding more nodes, which seems like less of a hassle, compared to changing some of these mechanics. Thank you for your help and checking through some of the possibilities though!

1 Like