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 /
  • Help Room /
avatar image
0
Question by MachoBrizzin · Mar 17, 2016 at 07:57 AM · transformplayerplanetatmosphere

How to Increase Value as Player Approaches

I am creating a space game in which the player will traverse and explore a bunch of planets my team has built. For the atmosphere, I'd like to increase a value while the player approaches the planet from space. This value, when it's higher, will make the planet look less foggy when they arrive on the surface. When it is lower, the fog will increase. I'd like to somehow track the player's position and increase/decrease the value of the atmosphere depending on if the player is approaching or leaving the planet.

When the player approaches a world, they enter a sphere trigger collider that will initiate a bunch of functions to make gameplay on the world smooth (such as making the player and their ship children of the planet so they follow it's transform). I'd like to call this function while they are in this same trigger. So it'd be in OnTriggerStay. Since they'd become a child of the planet, that means their transform would decrease the closer they get to the planet (it'd get closer to 0, 0, 0), and I want this to increase the value on the atmosphere script. So the closer the player's transform is to the planet, increase the fog value.

Stuff like this has always stumped me. Any suggestions? I apologize if I'm not being too clear.

Comment
Add comment · Show 4
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 Rajeesh_AR · Mar 17, 2016 at 10:55 AM 2
Share

Hi @DaAwsumPiderman , I understood a little. From that, you need some thing to happen (less fog value) when the player reaches near the planet.

void Update () { float distance = Vector3.Distance (object1.transform.position, object2.transform.position); }

From this you will get the distance between the player and planet. Using that, you could do the other options.

avatar image Salmjak Rajeesh_AR · Mar 17, 2016 at 11:00 AM 0
Share

For performance sake DaAwsumPiderman should use Vector3.sqr$$anonymous$$agnitude() since the value will probably be updated a lot (each frame). Although this might cause unwanted effects if the fog-effect is a direct cause of the distance (since sqr$$anonymous$$agnitude is the distance squared the fog-effect will have exponential growth/decay if you use something like float fog = 1/Vector3.sqr$$anonymous$$agnitude();)

avatar image MachoBrizzin Rajeesh_AR · Mar 17, 2016 at 06:59 PM 0
Share

@Rajeesh_AR

This allows me to find the distance, but it slows my game down significantly. What I'm looking for is a way to decrease a value as another value increases. I need to decrease the fog float (which will increase my custom fog...) as the player's distance from the planet increases. Thanks for your reply though! I appreciate the help. Do you know how I can accomplish the decrease & increase thing?

avatar image Salmjak MachoBrizzin · Mar 18, 2016 at 08:29 AM 0
Share

@DaAwsumPiderman Did you even read my comment? Use Vector3.Sqr$$anonymous$$agnitude! It's faster than Vector3.Distance.

Also I answered you question. 1/Vector3.sqr$$anonymous$$agnitude is a value that will DECREASE when sqr$$anonymous$$agnitude INCREASES.

0 Replies

· Add your reply
  • Sort: 

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

61 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

Related Questions

Can I set a halo of light so that it stays lit when the camera is near it 0 Answers

Move Character in the way he is facing.,Make character move in way he is facing. 1 Answer

how to load browsed video name in canvas? 1 Answer

Player teleport not working 0 Answers

Diagonal character movement 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