How to Move an NPC from anyplace to a specific place in 2D?

Hello, I’m making a 2D game where the player controls many characters by giving commands with the mouse. The scene is a cross section of a space ship (with multiple floors with stairs connecting them) with various character sprites on board. The spaceship moves around the screen, the sprites with it, of course. It doesn’t move a lot, mostly bobs around and changes pitch.

I want to be able to command crew by clicking buttons on the HUD. For Example, if the player clicks on a button that says “Abandon Ship”, then I want the characters to walk from wherever they are standing to the escape pod which will always be in the same place, relative to the ship.

I am able to find the Characters positions relative to the ship, but I can’t figure out how to get them there. If one is on the 3rd level of the ship and the escape pod is on the first level - I can’t get him to walk to the first set of stairs, descend, then to the next set of stairs, descend and then walk to the pod. See picture for more details

33471-stairs.png

I’m an experience programmer but new to C#, Unity and graphical programming. Any help would be most appreciated. Thanks so much

RayJr

One method is to use the waypoints. You can create waypoints in your game map like one waypoint at the start of the ladder and then second at the end of the ladder. You can add as many waypoints as required. Now you can store these waypoints in an array or List.

Now move your NPC from it current position to the closest waypoint on its floor then from there you can move it using another closest waypoint to the current waypoint and so on till you reach your pod. You can simply use any movement methods like MoveTowards.

Remember, more the number of waypoints will allow you to have more accurate movement but will require more computation. You can decide the waypoints as per your need.