• 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 jessee03 · Apr 27, 2012 at 12:07 AM · arrays

array of positions

How would you go about creating an array of stored positions that a player can move to?

Also make it so the player cannot move to a position that has a wall or an enemy on it?

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 Berenger · Apr 27, 2012 at 12:23 AM 0
Share

We need more information. You don't want to use physic behaviors I suppose ?

avatar image jessee03 · Apr 27, 2012 at 01:06 AM 0
Share

It's a 2d game. The world is generated with textured planes. I have a randomized code that picks if it should spawn a floor or wall. $$anonymous$$y question would be how do I store each one into an array? So if the location is [0,0] and it generates a floor then mark that spot in the array as a 0. Also it needs to specify where the location is as well. That way if my player is moving to [0,0] then the program will know it's okay for the player to move here.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by aldonaletto · Apr 27, 2012 at 12:26 AM

Usually you create empty game objects (waypoints) and place them at the desired positions in the Scene view. You can get all of them in a GameObject array with FindGameObjectsWithTag at Start, or create a public Transform array in the player script and drag the waypoints to it in the Inspector.
To check if something is blocking some waypoint, use a LineCast - if it returns true, something is blocking the way:

  if (Physics.LineCast(transform.position, waypoint.position)){
    // something is blocking the way!
  }
Make sure each waypoint is at approximately 1 unit above the ground - if too high or below the ground, LineCast may return wrong results.
Comment
Add comment · Show 1 · 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 jessee03 · Apr 27, 2012 at 12:51 AM 0
Share

well I'm developing a 2d game with textured planes. Once each position is randomly generated I need some way to store each location in an array. So if it's a wall you will be able to check where you on the grid and then access the array to see if a wall is on the next tile. So something like if ground is generated then place it in the array as a 0 or if it's a wall then it's a 1. I'm just unsure how too store and keep track of all of this.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

List problem? 2 Answers

How to create an array of touch positions? 1 Answer

Distance error: Cannot cast from source type to destination 0 Answers

Can I change inspector 'Element 0' to something else? 6 Answers

Iterating a GO through an array of transform positions 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