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 GameCreator001 · Oct 28, 2011 at 12:55 AM · watereffects

Water Effects

I have unity pro and im using the Water4Advanced Example they give you, how can i make it where when my player goes under water the screen has a little blue effect and where gravity lowers. Ive heard of people using some function like OnCollidisionEnter or something like that but i have no idea how i would do this myself. All help is appreciated...

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

2 Replies

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

Answer by aldonaletto · Oct 28, 2011 at 02:00 AM

I'm using a trigger box under the water plane, and comparing the camera position to the water plane level; when the player enters the trigger, a variable inWater is set and the water plane level is defined. The player speed is reduced when inWater is true, and if the camera position is lower than the water plane level, the underwater effects are activated - a blue fog, with the skybox replaced by a solid color (the same fog color); when the camera returns to above the water, the original settings are restored, and when the player exits the trigger, inWater is reset - something like the script below (let's call it Underwater.js), to be attached to the player:

public var uFogColor = Color(0.05, 0.36, 0.58, 1); // underwater fog public var uFogDens: float = 0.05; // underwater fog intensity // save current settings private var dFogColor: Color; private var dFogDens: float; private var dFogEn: boolean; static var inWater = false; // read this in the movement script to control the player speed public var waterLevel: float; private var underWater = false; private var lastUWater = false;

function Update(){

var cam = Camera.main; underWater = inWater && cam.transform.position.y < waterLevel; if (underWater != lastUWater){ // only change settings when underWater changed lastUWater = underWater;
if (underWater){ dFogColor = RenderSettings.fogColor; // save the current settings dFogDens = RenderSettings.fogDensity; dFogEn = RenderSettings.fog; RenderSettings.fog = true; // turn fog on... RenderSettings.fogDensity = uFogDens; // with the underwater settings RenderSettings.fogColor = uFogColor; cam.clearFlags = CameraClearFlags.SolidColor; // sky vanishes in the fog cam.backgroundColor = uFogColor; } else { RenderSettings.fog = dFogEn; // restore original settings RenderSettings.fogDensity = dFogDens; RenderSettings.fogColor = dFogColor; cam.clearFlags = CameraClearFlags.Skybox; } } }

function OnTriggerEnter(col: Collider){ if (col.tag == "Water"){ waterLevel = col.bounds.max.y; inWater = true; } }

function OnTriggerExit(col: Collider){ if (col.tag == "Water"){ inWater = false; } } In the player movement script, read inWater to know which speed to use:

function Update(){
  var speed = normalSpeed;
  if (Underwater.inWater) speed = waterSpeed;
  // move the character with the speed selected
  ...
}
Since you have Pro, you can use other effects as well - like Blur, for instance.
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 Rydrako · Oct 28, 2011 at 02:48 AM 0
Share

So you don't need Pro to do what your doing? Awesome!

avatar image GameCreator001 · Oct 28, 2011 at 02:48 AM 0
Share

i use c# for the playercontroller and i converted all of your code to c# other than i have to questions...

public var uFogColor is that suppose to be a string and var cam = Camera.main; is that suppose to be a transform or GameObject?

avatar image GameCreator001 · Oct 28, 2011 at 05:44 AM 0
Share

nvm i got most of it set up and just noticed that uFogColor is a float and fixed var cam but i get this error Assets/ShiftedIrony Assets/Scripts/Player/PlayerController.cs(28,41): error CS1519: Unexpected symbol `0.36' in class, struct, or interface member declaration and its with this line public float uFogColor = 0.05f, 0.36f, 0.58f, 1; // underwater fog ive had that var set up like this too and it still gives that error public float uFogColor = (0.05f, 0.36f, 0.58f, 1); // underwater fog

avatar image ghazza · Apr 19, 2013 at 05:41 PM 0
Share

thank you so much this worked perfectly for me ! i have a question though, i have a simple plane for the moment and i don't know how to proceed to make it like actual water/ocean, any clue ? thanx

avatar image
0

Answer by gfr · Oct 28, 2011 at 01:55 AM

You can use colliders set to be triggers and handle OnTriggerEnter() / OnTriggerExit().

In your handlers you would:

  • enable/disable screen effects (blur, color, ...)

  • set a flag indicating wether your character is under water

Then you can adjust the falling speed in your character controller according to that flag (assuming no rigid body).

Comment
Add comment · 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

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Elementes like in "from dust" 1 Answer

Water effects crash mobile platform 1 Answer

How to animate Pro Water3 0 Answers

Water4 looks like fog; no surface 1 Answer

Gray water problem 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