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 Renoclaf · May 11, 2013 at 11:52 AM · c#listgridtargeting

Targeting multiple tiles in grid, updating with player movement

Hi all,

Currently working on a grid based project which requires the player to destroy 'bad' tiles, I'm having trouble figuring out how to handle the targeting system as it needs to update as the player(yellow and blue orb) moves with respect to its rotation. I made an attempt as you can see by the yellow outlined tiles. It is however very crude as I'm accessing a static list held by a manager object from the player script and then running a for loop to check the list against the player position(this is all being called through update, I know this is bad but I couldn't think of an alternative). alt text

If anyone could offer any sort of advice in terms of the approach I should take to this problem I would be extremely appreciative.

Thanks,

Renoclaf

untitled-2.jpg (76.3 kB)
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Owen-Reynolds · May 11, 2013 at 03:04 PM

Sounds fine to me. Since it's based on position and rotation, then every frame all 49(7x7 area?) nearby objects could possibly change. That means you absolutely have to touch each object each frame. 49 isn't that big a number (not like 100 units are all doing that.)

If the rotation is in set steps, you could do the math only when you change tiles or spin, but that would give tiny lag spikes. Running every frame would smooth it out.

For the "I'm too far away, uncolor me" objects, maybe call a slow coroutine when you first color something, which checks for "too far away." Check more frequently as distance from player increases? Have a flag "I'm running my too far away checker," to avoid double-calling. That would give a pretty, staggered winking-out effect. Alternative is to add colored items to your own watch list, but, really, the coroutine does the same thing.

Comment
Add comment · Show 9 · 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 Renoclaf · May 11, 2013 at 03:45 PM 0
Share

Hey Owen, thanks for the reply. I forgot to specify in the original post that the grid is in fact a lot larger than this 30 x 30 at least. The main reason for me posting was that when I implemented this I was using 90%+ CPU on an i7. I do have a number of debugs running in update but I'm not sure how much that would impact things. Do you still think this is the best approach?

Thanks.

avatar image Owen-Reynolds · May 11, 2013 at 03:58 PM 0
Share

Are you coloring the entire grid each frame? I assumed only "nearby" tiles were colored.

To color all, could run a loop every frame to color nearby. Then color "6-away" on even frames, "7-away" on odd, "8-away" on multiples of 3 ... . $$anonymous$$ight look nice in that you'd see color changes "fan out" from you.

avatar image Renoclaf · May 11, 2013 at 10:46 PM 0
Share

All of the tiles are initially set to blue, the idea behind the dark tiles is that they are an infection so I need to have consistent coloring. As it works now the grid is created at the beginning of the game based on user input in terms of size. From here

  • All tiles are then added to a 'grid' list

  • The perimeter tiles are added to a 'perimeter' list

  • The 'light'(blue tiles) list is made (gridlist - perimlist)

  • A coroutine is started which randoms a perimeter tile every 'X' amount of seconds which is then added to a 'dark'(black) list

  • The next block in the co routine randoms between finding the closest and furthermost 'Z' number of draft tiles which are added to a temporary list

  • Finally 'x' number of tiles are randomly chosen from the temporary lists, which then starts a function which sends the specific(based off name) tiles a message telling them to change to one of the textures they hold.

Just though i'd clarify my process in case this would have some impact. I like the idea of setting the closest tiles color, however in this case I really need to stick to this good / bad infection narrative direction.

Thanks again.

avatar image Owen-Reynolds · May 12, 2013 at 02:42 AM 0
Share

If things are only changing occasionally, on your schedule, time probably isn't an issue. Four length 30 sides isn't that big a number. One trick, to smooth time out over frames, is to have the coroutine yield one frame every 20 or so tiles (a small pain, since you have to under estimate frames until next big change.)

avatar image robertbu · May 12, 2013 at 03:55 AM 0
Share

Are you sure it is the targeting code that is causing you the performance issues? As I read through what you are doing, I see several potential performance pitfalls. In particular if you are really changing the texture of each square (ins$$anonymous$$d of using a texture atlas and changing the UV coordinates), you will be generating up to 900 drawcalls for the plane (ins$$anonymous$$d of one batched call for a texture atlas solution). And you could boil this app down to a single mesh/game object and just change the uvs.

As for the targeting, given the regular nature of your board, I'm sure there are highly efficient methods. But how good is just leveraging Unity? That is, if you put a box collider on each tile and did a RaycastAll(), would it be good enough?

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

14 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

Related Questions

Problem with targeting system 0 Answers

Grid 'Infection' though lists c# 0 Answers

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

A node in a childnode? 1 Answer


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