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
1
Question by Jinxology · Apr 04, 2014 at 07:48 PM · 2dtilesline of sight

2D Line of Sight with tiles

I'm making a top-down view game as seen below. The tan grid background is the base art, and as a player (P) moves and uncovers tiles, I will be using a sprite for the bordering walls as they become visible.

alt text

The map tiles with the red X's will not show unless the player has vision.

I need a technique for determining which tiles are visible. I've written a lot of line of sight (LoS) code over the years, but I'm wondering how best to achieve this in Unity with 2.5D. It feels silly to code 3D stuff that may already be built in.

The only solution I've come up with so far was to manually put in some invisible box colliders as "walls" wherever the black lines are, then do something with line casting from the player. Anyone have any suggestions for how best to solve this problem? I'd really appreciate some advice here.

samplemap.png (179.1 kB)
Comment
Add comment · Show 5
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 njt1982 · May 22, 2017 at 10:38 PM 0
Share

did you ever find a solution for this?

avatar image Jinxology · May 23, 2017 at 12:00 AM 0
Share

I ended up doing what I suggested above. At runtime, I create a box collider on every square. I also create box colliders for the walls. Then, I cast a bunch of 2D rays out from the player to see what she can see, with the walls blocking rays. The more rays, the better, as it will account better for situations where you can barely see around a corner.

avatar image gosaints70 Jinxology · May 23, 2017 at 12:01 AM 0
Share

I recommend using Renderer.isVisible but sadly my answer is not approved yet.

avatar image Jinxology gosaints70 · May 23, 2017 at 12:28 AM 0
Share

Where is your answer posted? I don't see it.

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by gosaints70 · May 25, 2017 at 02:53 PM

If the tiles have a Renderer attached to them you can use the built-in variable Renderer.isVisible to check if they're in the camera's view.

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 njt1982 · May 25, 2017 at 03:35 PM 0
Share

Not sure that'd work for a top-down game unless you attach some kind of secondary camera to the player?!

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

24 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

Related Questions

Need help finding a library/solution for efficient 2D tilemap rendering, collisions and interaction. 1 Answer

Pixel Perfect 2 Answers

find prefabs that extend Base Class c# 0 Answers

Is there another way of making a Top-Down-2D Map other than generating hundreds of Spriterenderes? 1 Answer

why is unity set tile not working? 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