Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by RayJr · Oct 10, 2014 at 03:37 AM · 2dpositionmovingnpc

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

alt text

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

RayJr

stairs.png (2.9 kB)
Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image MrSoad · Oct 20, 2014 at 12:31 PM 0
Share

Unity has in built "path finding", I have never used it but it may do what you need for this.

avatar image RayJr · Oct 20, 2014 at 01:10 PM 0
Share

Hi, I looked into that a bit but could only see it in 3d, as in a large flat space with obsticles.

1 Reply

· Add your reply
  • Sort: 
avatar image
5
Best Answer

Answer by HarshadK · Oct 20, 2014 at 01:21 PM

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.

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image RayJr · Oct 20, 2014 at 01:50 PM 0
Share

Ah, that sounds like what i'm looking for. Are Waypoints an actual object/parameter, or do you code them from scratch sort of thing ?

Thanks so much :)

avatar image HarshadK · Oct 20, 2014 at 01:54 PM 0
Share

You can place empty objects at the place where you want your waypoints to be. Set tags of these game objects to be something like WayPoints. Now you can get positions of all those game objects which you can then use to move your NPC.

Or you can write your waypoint positions in your script also. But this will make changes difficult each time you move an object related to the waypoint or something.

Better go with the first method.

avatar image RayJr · Oct 20, 2014 at 02:42 PM 0
Share

BA$$anonymous$$! I'm in business. Thanks!! ^_^

avatar image MianAbdul RayJr · May 14, 2017 at 05:24 AM 1
Share

Here is my problem which is that I want to make my lower cube (enemy) use gravity and mass, and my cube never moves in straight down/Up in y-axis it just looks that cube is jumping down or jumping up on horizontal walls and follow the duck (Player). I am using "A* pathfinding". The image is for just understanding. Ins$$anonymous$$d of using the red path the cube following the green path as shown in the image. I am very thankful in advance for helping me.alt text

capture.png (24.3 kB)

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

2D - Passing Through Colliders 1 Answer

Move towards mouse position on button down (2D)? 1 Answer

How to drag-and-stretch a 2D sprite in local space? 0 Answers

Move towards current direction on the Z axis (2D) 1 Answer

An easy way to get the global position from a child object 5 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges