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
0
Question by dodi · Jul 07, 2014 at 10:25 AM · gameobjecttilelocation

Best way to determine if there is a gameobject in multiple locations?

Hi all. How do I determine if there are no gameobjects in set locations?

I'm making a 2d tile based game and I want to check if there are any gameobjects in a set coordinate. I have no problems checking if there are any gameobjects in a location. I just ran a foreach for every gameobject with certain tags and do actions if they are in certain tiles. However, I don't know what to do for empty tiles.

I'm planning to make an empty gameobject with a collider then iterate it through the locations and check if there are any trigger/collision to other gameobjects. Should I got through this method or are there any simpler way to do this? Thank you in advance.

Comment
Add comment · Show 3
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 lukas_balaz · Jul 07, 2014 at 10:37 AM 0
Share

I dont understand ... why dont you run foreach for every gameobject with certain tags as you wrote ?

avatar image dodi · Jul 07, 2014 at 11:12 AM 0
Share

I have a 2d array that shows the content of each tile. It should have a value of 2 if there is a player character, 1 if there is a wall, etc.

Foreach would work if I have a gameobject in every location/tile but I don't. I want to know which locations has no gameobjects so I can set the values in the array.

After reading your comment I just thought of putting empty gameobjects with the tag "empty" on locations with no players, enemies, walls, etc. Would it be easier if I would make gameobjects with the tag "empty" for empty tiles rather than checking if there any gameobjects in set locations/tiles?

avatar image lukas_balaz · Jul 07, 2014 at 11:52 AM 0
Share

why dont you intialize array with 0, and then run foreach for every object and change number of every tile where something is? So empty tiles have value 0.

1 Reply

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

Answer by Andres-Fernandez · Jul 07, 2014 at 12:10 PM

Well, I can think of a couple of solutions.

First and easiest: just have a logical representation of your map. Being a 2d array, text file, whatever you want. Make your objects update your logical map whenever they move/change position and then you only need to check your logical map at the desired position.

Second: Create an array of tile positions on top of the tiles and send raycasts from each tile position to the tile. If collides with any object, then the tile is occupied. Else, it's free.

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 lukas_balaz · Jul 07, 2014 at 02:05 PM 0
Share

I think your first solution isnt the easiest, but it is the best certainly. Sending raycast, creating empty objects or even triggers is not good.

avatar image Andres-Fernandez · Jul 08, 2014 at 06:44 AM 0
Share

Well, first one seems the easiest to me. I would go for the 2D array (tile based games are perfect for that kind of logical representation).

For the second one you don't need to create anything, just have a Vector3 array to send the raycasts from and one layer to check for the characters. No triggers or anything. If your characters have colliders on, just send the raycast. Although it would cost a lot of time, that's for sure.

avatar image dodi · Jul 08, 2014 at 02:18 PM 1
Share

Thanks. I did the first one

avatar image lukas_balaz · Jul 08, 2014 at 08:32 PM 0
Share

yes, the first one is most effective, so it is the best for me. But you need to change the array every time when anything moves, so you can do some bugs easily. That is why I dont think it is most easy (something is easy for me if it is easy to code, but I like doing things effective)

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

Spawning GameObjects with help of classes --- Attaching classes to GameObjects 1 Answer

Instantiating Multiple Game Objects to the Position of a Current GameObject 2 Answers

How to apply more than one trigger on a single gamebject 1 Answer

using Contains(gameObject) to find and destroy a gameObject from a list 2 Answers

Please help. How do I add a 3D Object at a specific location in the GO Maps package? 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