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
0
Question by unity_qyNAJ9CdbDf9rw · Sep 17, 2019 at 03:46 AM · lightingdistancegriddetect

Change Lighting of grid base on distance from player.

Hello !

I want my grid is darker when far from player, lighter when nearby player, Unvisiable (dark) when not discovered yet (Or there is line of tree block player view (like a tree inside a jungle)). Like this : alt text

Can you help me this problemt ? I dont know how to change the light of grid, detect if there is a line of tree.

Thanks for advice !

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
Best Answer

Answer by toddisarockstar · Sep 17, 2019 at 05:19 AM

you can calculate squares in a circular pattern using the distance formula.

this would print out all the squares around a given coordinate at a given distance:

     void GetSquaresNearPoint (int x, int y, int dist){
         int xx = dist*2;
         while(xx>0){xx--;
             int yy = dist*2;
                     int xd = xx - dist;
             while(yy>0){yy--;
                 
                 int yd = yy - dist;
                 if((xd*xd)+(yd*yd)<dist*dist){
                     print((x+xx-dist)+","+(y+yy-dist));
                 
                 }
         
             }}
       }


in a game like this there should be some system in place to hold data for each square to tell if it is able to be lit or not.

Comment
Add comment · Show 7 · 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 alireza97 · Sep 17, 2019 at 07:35 AM 0
Share

this function should be called in Update???

is there any way to improve performance because in the game like this performance is everything.

I have the same problem and still, couldn't find the best way to do that.

avatar image toddisarockstar alireza97 · Sep 17, 2019 at 11:04 AM 1
Share

there would be no reason to call this every frame!!! in a situation like the above picture this function shoulnt be called more than once each time the player changes what square he is standing on.

and Yes ! There is a couple ways to improve the speed of my answer! if you are always checking a fixed distance then the circular pattern could be stored ahead of time into an array of coordinates. Then when you light the spaces, you could simply page through this array and add the players position. this would avoid the distance calculations.

also anytime you can get by with using a square pattern ins$$anonymous$$d of a circular pattern for whatever you are doing, You can remove the distance calculations and it's much faster.

avatar image alireza97 alireza97 · Sep 18, 2019 at 11:32 AM 0
Share

Thanks.

$$anonymous$$y Game doesn't exactly like this.

It's something like 'DOTA2' and I'm trying to have the best performance so if you have any idea please help me.

avatar image Pangamini · Sep 17, 2019 at 08:19 AM 0
Share

Please please please change

 if($$anonymous$$athf.Sqrt((xd*xd)+(yd*yd))<dist){

at least to

  if(((xd*xd)+(yd*yd)) < dist*dist){

Sqrt is very slow and completely unnecessary here You could also move the X related stuff to the first loop, their values remain the same in the Y loop

avatar image toddisarockstar · Sep 17, 2019 at 10:46 AM 0
Share

@Panga$$anonymous$$i is correct and i have updated my answer to show his suggestion.

avatar image Pangamini · Sep 17, 2019 at 11:05 AM 0
Share

Also consider doing the whole thing on the GPU, I'd say this is a perfect candidate

avatar image unity_qyNAJ9CdbDf9rw · Sep 18, 2019 at 01:38 AM 0
Share

Thanks you ! So how can i change the light of one grid ?

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

154 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Change Lighting of grid base on distance from player. 0 Answers

Terrain shadow distance and lighting problem 0 Answers

Detect if player is in range? 2 Answers

Hexagon-Grid Distance 2 Answers

Reflected light not showing at a certain distance 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