Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
1
Question by deprofundiis · May 04, 2016 at 02:02 PM · 2dmovementphysics2dnavigationadventure

What is the most efficient way to create a "walkable"area for 2D games?

Hi everyone,

This is just a theoretical question but, I am thinking of starting a 2D game and would love to get your input on what is the best solution (performance-wise) to define walkable areas (basically the are in which a player may move a character and where agents move) for a 2D game like Sword & Sorcery or any other second-person perspective games.

Please consider both point & click movement as well as realtime (X&Y axis).

  • use colliders and test every cycle before moving;

  • adultered navmesh 2D hack;

  • any other...

Thanks

Comment
Add comment
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

2 Replies

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

Answer by TTTTTa · May 04, 2016 at 06:36 PM

@deprofundiis One solution is to have a special Tag for the walkable floor areas. Say you have a floor that the player is allowed to walk on. Give it a tag named "Walkable". Then your script is generating Raycasts downward to detect the tag of the current floor. If the floor below the player does not contain the tag "Walkable", then the player is not allowed to move there, IF the floor below the player does contain "Walkable", then the player can move to that location.

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 deprofundiis · May 04, 2016 at 10:20 PM 0
Share

True, but is it the most efficient way? Will it cause issues if I decide to port it to mobile because of crappy processors?

avatar image TTTTTa deprofundiis · May 04, 2016 at 10:54 PM 0
Share

It could very well be the most efficient way. Doing one raycast per frame is not going to have any noticeable effect of performance. The Unity character controller does at least one per frame to even deter$$anonymous$$e if the character isGrounded anyways.

avatar image deprofundiis TTTTTa · May 04, 2016 at 10:57 PM 0
Share

Thanks for your input. $$anonymous$$uch appreciated.

Show more comments
avatar image
2

Answer by FortisVenaliter · May 04, 2016 at 05:19 PM

In my experience, when Unity's NavMesh won't cut it, Node- or Grid-based A* algorithms tend to be the best balance between ease of setup and final performance. Wikipedia actually has a really good article on A*, complete with pseudocode.

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 deprofundiis · May 04, 2016 at 05:45 PM 0
Share

Thank you so much for your answer.

What if I want to do realtime movement, i.e. using X & Y axis input? What do you think would be the best solution?

avatar image FortisVenaliter deprofundiis · May 04, 2016 at 06:00 PM 0
Share

Well, if you're receiving input, why do you need pathfinding?

avatar image deprofundiis FortisVenaliter · May 04, 2016 at 06:30 PM 0
Share

Not pathfinding per se but I do need to detect valid movement input.

In this example, I don't want my character to fly all over the screen. If it is on the top of the mountain I want to limit that movement to the top area only.

Show more comments

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

48 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Why Rigidbody 2d doesnt stop sliding? 2 Answers

Changing only vertical speed on NavMeshAgent? 0 Answers

Physic function doesn't work in different resoultions 0 Answers

Move 2D ground up and down 1 Answer

Player stops moving upon collision 0 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