Search Unity

  1. We've closed the job boards. If you're looking for work, or looking to hire check out Unity Connect. You can see more information here.
    Dismiss Notice
  2. Unity 2017.3 has arrived! Read about it here.
    Dismiss Notice
  3. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Access Terrain Wind Setting and Wind Zone in Unity3D 3.0.02f

Discussion in 'Scripting' started by tigershan, Sep 17, 2010.

  1. tigershan

    tigershan

    Joined:
    Jul 29, 2010
    Posts:
    72
    I am trying to access terrain wind settings for bending factors in realtime, however it's not avalible.

    Same goes for the wind turblence script that's in Unity 3.0, I don't see a way to access that script either.

    How Can I get any access to this?
    is no access to these properties in the terrain or terrain data class.

    Which shader under terrain would I need to modify,
    Do I have to first find the shader manipulating the brushes, then using a script access that shader and then bending it through that script by setting a new variable I create?
     
  2. tigershan

    tigershan

    Joined:
    Jul 29, 2010
    Posts:
    72
    So far, WindZone is solved.

    Accessing WindZone (keywords):
    Class: WindZone
    Parameters: windPulseMagnitude, windPulseFrequency, etc.
     
  3. tigershan

    tigershan

    Joined:
    Jul 29, 2010
    Posts:
    72
    why have unity guys changed the WindZone class to something else or private, I can't find the namespace WindZone anymore or access it in script in 3.0.02f-_-', any documentation on it?
     
  4. andeeeee

    andeeeee

    Joined:
    Jul 19, 2005
    Posts:
    8,768
    WindZone is in the scripting manual (Object > Component > Wind Zone).
     
  5. tigershan

    tigershan

    Joined:
    Jul 29, 2010
    Posts:
    72
    Not sure what you mean, I mean I can't call the WindZone class under script and adjust those WindZone parameters in realtime in 3.0.02f
     
  6. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    4,304
    No there is not such thing as WindZone in the Scripting Manual. Nor is there information anywhere on how/if we can hook up other things to wind zones (I'm guessing a vertex map is used to find which vertices should move and how much?).
     
  7. Antitheory

    Antitheory

    Joined:
    Nov 14, 2010
    Posts:
    549
    Yeah that's pretty annoying. I think windzones are a good idea, however we need to access to them if we are to make use of them for custom objects. I have some rain which is affected by the wind, including some faux turbulence, however there is no way to link this with the Unity windzones because I can't access it through scripting. Another annoying thing is that the detail objects on the terrain aren't affected by windzones... they're almost unusable for that reason alone.
     
  8. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,596
    Wind Zones need to become accessable. not just for the required dynamic environments (which up to a given degree can be compensated for through the terrain wind settings) but also because they are fundamental for anything like a visually appealing explosion on a terrain where a spherical windzone just is a must.
     
  9. Antitheory

    Antitheory

    Joined:
    Nov 14, 2010
    Posts:
    549
    Exactly. It seems impossible to fake it with scripts too as particles from a single emitter don't have independent velocities. I am racking my brain thinking how to make a snow "flurry"... perhaps I have to use multiple emitters. I really wish that objects had a physics property to them which enabled them to be affected by windzones.
     
  10. Seto

    Seto

    Joined:
    Oct 10, 2010
    Posts:
    130
    Yes. The windzone should be public.
     
  11. alexzzzz

    alexzzzz

    Joined:
    Nov 20, 2010
    Posts:
    1,295
    Hint: Wind can be controlled using WindZone's rotation: it looks forward ― full wind, it looks down ― zero wind. All other WindZone's features can be easily simulated using this technique.
     
    Last edited: Mar 6, 2011
  12. Nividica

    Nividica

    Joined:
    May 19, 2011
    Posts:
    11
    Hmm, I as well need access to the wind settings, as they play a vital part in my weather simulations.
    Im going to do some digging and see if I can find anyway to access the windzone via reflection.
     
  13. Nividica

    Nividica

    Joined:
    May 19, 2011
    Posts:
    11
    After a fair bit of work digging around with the reflection system, I created a class that gives you control over a WindZone, and a child class that gives you a clean script to program in as well as example code of usage.
    Be sure to attach the "WindZoneController.cs" script to the same game object that has a windzone component, and remember to call base.Init() in the Start() function

    Note: I did not link against the `Mode` setting

    ScriptableWindzoneInterface.cs
    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4. using System.Reflection ;
    5.  
    6. // Provides a scriptable interface to a windzone
    7. /* Change Log
    8.  * 05/25/11 Created by Nividica
    9.  *          As Unity provides no way to access a windzone via
    10.  *              script, I am digging around in the reflections
    11.  *              to pull out its memeber information and write
    12.  *              getter and setter methods.
    13.  *          Finished writing the get/set methods for everything
    14.  *              except the Mode.
    15.  */
    16. public class ScriptableWindzoneInterface : MonoBehaviour { 
    17.     // Private vars ===================================
    18.    
    19.     // The windzone component
    20.     private Component m_WindzoneComponent ;
    21.    
    22.     // The system qualified type of the windzone
    23.     private System.Type m_WindzoneType ;
    24.    
    25.     // Used to pass an argument to WindZone setter functions
    26.     object[] m_WindZoneArgs = new object[1] ;
    27.    
    28.     // Public properties ==============================
    29.    
    30.     // `radius`
    31.     public float Radius {
    32.         get
    33.         {
    34.             // Return the value of `radius`
    35.             return (float)GetWindZoneValue( "get_radius" ) ;
    36.         }
    37.         set
    38.         {
    39.             // Set the argument
    40.             m_WindZoneArgs[0] = value ;
    41.            
    42.             // Set the value of `windMain`
    43.             SetWindZoneValue( "set_radius" , m_WindZoneArgs ) ;
    44.         }
    45.     }
    46.    
    47.     // `windMain`
    48.     public float WindMain {
    49.         get
    50.         {
    51.             // Return the value of `windMain`
    52.             return (float)GetWindZoneValue( "get_windMain" ) ;
    53.         }
    54.         set
    55.         {
    56.             // Set the argument
    57.             m_WindZoneArgs[0] = value ;
    58.            
    59.             // Set the value of `windMain`
    60.             SetWindZoneValue( "set_windMain" , m_WindZoneArgs ) ;
    61.         }
    62.     }
    63.    
    64.     // `windTurbulence`
    65.     public float WindTurbulence {
    66.         get
    67.         {
    68.             // Return the value of `windTurbulence`
    69.             return (float)GetWindZoneValue( "get_windTurbulence" ) ;
    70.         }
    71.         set
    72.         {
    73.             // Set the argument
    74.             m_WindZoneArgs[0] = value ;
    75.            
    76.             // Set the value of `windTurbulence`
    77.             SetWindZoneValue( "set_windTurbulence" , m_WindZoneArgs ) ;
    78.         }
    79.     }
    80.    
    81.     // `windPulseMagnitude`
    82.     public float WindPulseMagnitude {
    83.         get
    84.         {
    85.             // Return the value of `windPulseMagnitude`
    86.             return (float)GetWindZoneValue( "get_windPulseMagnitude" ) ;
    87.         }
    88.         set
    89.         {
    90.             // Set the argument
    91.             m_WindZoneArgs[0] = value ;
    92.            
    93.             // Set the value of `windPulseMagnitude`
    94.             SetWindZoneValue( "set_windPulseMagnitude" , m_WindZoneArgs ) ;
    95.         }
    96.     }
    97.    
    98.     // `windPulseFrequency`
    99.     public float WindPulseFrequency {
    100.         get
    101.         {
    102.             // Return the value of `windPulseFrequency`
    103.             return (float)GetWindZoneValue( "get_windPulseFrequency" ) ;
    104.         }
    105.         set
    106.         {
    107.             // Set the argument
    108.             m_WindZoneArgs[0] = value ;
    109.            
    110.             // Set the value of `windPulseMagnitude`
    111.             SetWindZoneValue( "set_windPulseFrequency" , m_WindZoneArgs ) ;
    112.         }
    113.     }
    114.    
    115.     // Public functions ===============================
    116.    
    117.     // Find and link against the windzone
    118.     public void Init () {
    119.        
    120.         // Get the windzone of this game object
    121.         m_WindzoneComponent = GetComponent("WindZone");
    122.        
    123.         // Ensure there was a windzone to link to
    124.         if ( m_WindzoneComponent == null ) {
    125.             // Log the error
    126.             Debug.LogError( "Could not find a wind zone to link to: " + this ) ;
    127.            
    128.             // Disable this script for the remainder of the run
    129.             this.enabled = false;
    130.            
    131.             // Stop here
    132.             return ;
    133.         }
    134.        
    135.         // Get the system qualified type
    136.         m_WindzoneType = m_WindzoneComponent.GetType() ;
    137.        
    138.     }
    139.    
    140.     // Private functions =============================
    141.    
    142.     // Set a WindZone property value
    143.     void SetWindZoneValue ( string MemberName , object[] args ){
    144.         // Call the setter
    145.         m_WindzoneType.InvokeMember(
    146.                                     MemberName ,
    147.                                     BindingFlags.InvokeMethod | BindingFlags.Instance ,
    148.                                     null ,
    149.                                     m_WindzoneComponent ,
    150.                                     args ) ;
    151.     }
    152.    
    153.     // Get a WindZone property value
    154.     object GetWindZoneValue ( string MemberName ){
    155.         // Call the getter
    156.         return m_WindzoneType.InvokeMember(
    157.                                            MemberName ,
    158.                                            BindingFlags.InvokeMethod | BindingFlags.Instance ,
    159.                                            null ,
    160.                                            m_WindzoneComponent ,
    161.                                            null ) ;
    162.     }
    163. }
    164.  
    WindZoneController.cs
    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. // Allows Control Over WindZone Component
    6.  
    7. // Note: The WindZone  This Script Must Be Attached To The Same Game Object
    8.  
    9. public class WindzoneController : ScriptableWindzoneInterface {
    10.  
    11.     // Use this for initialization
    12.     void Start () {
    13.         // Tell the ScriptableWindzoneInterface to initialize
    14.         base.Init() ;
    15.        
    16.         // Example: Log the current settings
    17.         Debug.Log( "The Starting Settings Of The Windzone Are: Main=" + WindMain
    18.                   + ", Turbulence=" + WindTurbulence
    19.                   + ", Pulse Magnitude=" + WindPulseMagnitude
    20.                   + ", Pulse Frequency=" + WindPulseFrequency ) ;
    21.     }
    22.    
    23.     // Update is called once per frame
    24.     void Update () {
    25.        
    26.         // Example: Setting each of the values
    27.         WindMain = Mathf.PingPong( ( Time.time / 2.0F ) , 1.0F ) ;
    28.         WindTurbulence = WindMain ;
    29.         WindPulseMagnitude = WindMain ;
    30.         WindPulseFrequency = WindMain ;
    31.         Radius = WindMain;
    32.     }
    33. }
    34.  
    35.  
    If you have any questions or problems let me know :D
     
  14. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,596
    I would preplan accordingly if you use this "hack".
    Its common for Unity that UT if they decide to not allow you on a function for the time or generally will make the class protected sealed cutting you out which basically prevents you from switching to any new version of Unity at all then.
    A lot of people had to learn this lesson the hard way when UT made many functions and classes protected or even private as well as sealed in 3.0 vs 2.6

    So if you use this you need to preplan for the situation where you might be forced to remain on the unity version you are using at the time, no 3.4 and newer.

    If you want long term savety, you might want to consider implementing a system that completely replaces the wind system and dynamically feeds a vertex shader for example, at least until WindZones become officially exposed
     
    Last edited: May 26, 2011
  15. Nividica

    Nividica

    Joined:
    May 19, 2011
    Posts:
    11
    Its true this a total hack-meat solution to the problem, and im genuinely hoping that in a future release the windzone component will indeed be scriptable. For now, and mostly for me, it will have to work. The weather system im working on already had the ability to determine the speed and direction of the wind, but no way to effect the tree's, which adds that touch of polish im looking for.
    (Should have mentioned this before) But if anyone does use it, please be advised this is not guaranteed to work with any future versions of unity. Just found a solution to my problem and decided to share.
    Thanks dreamora for pointing out the forward compatibility issues.
     
  16. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,596
    No prob and sorry if above came over in any way as harsh or alike. Edited above posting to reflect better what I wanted to imply and less what it potentially "transfered"

    Its definitely not meant like it.
    Wanted to thank you for sharing this "dirty" solution cause for those working on something thats meant to happen soon, its definitely going to work fine for the time being and for larger and longer projects you normally consider twice if you upgrade the engine midway through the project as bugs and generally regression can have nightmare side effects.
     
  17. alexfeature

    alexfeature

    Joined:
    Apr 1, 2010
    Posts:
    132
    Hey Guys,

    I have a different workaround to this problem that worked for me when I needed to make some explosions on terrains. It's not as flexible as Nividica's script but at the same time it shouldn't break with new releases.

    So, what I did was:

    1. Attached animation component to the object with the windzone;
    2. Disabled the wz and set the first frame to start with 0 values across all wz settings;
    3. Played with the time line and various settings to get the desired effect;
    4. Set Enabled to 1 in the frame where I wanted the effect to start;
    5. Set Enabled to 0 in the last frame to disable the wz;

    Finally I triggered the animation to start playing in a collision event handler in one of my other scripts.

    At first I didn't think this would work but the end result was far better than what I expected. There is tons of funky stuff you can do in the animation editor to make some very very nice explosion shock waves and such.


    Hope someone finds this useful.
     
  18. PeterB

    PeterB

    Joined:
    Nov 3, 2010
    Posts:
    266
    Another annoying thing is that the absence of WindZone as a type makes it impossible to work in UnityScript with #pragma strict active. With #pragma strict not turned on, it is possible, however, to do

    Code (csharp):
    1. var wz = GetComponent("WindZone");
    which means the WindZone component is accessible, though not through the type system.

    I very much doubt that the Unity developers purposely have decided not to expose WindZones, especially since there are recommendations in the manual on how to make trees respond to explosions by animating WindZone attributes in real time. However, this cannot be done in any way other than in UnityScript using dynamic typing. Looks like an oversight which ought to be corrected ASAP.
     
    Last edited: Jun 19, 2011
  19. AnomalusUndrdog

    AnomalusUndrdog

    Joined:
    Jul 3, 2009
    Posts:
    1,409
    I'm hoping WindZone gets exposed to script officially too.

    I think this is one of the things they've left behind. I was thinking the windzone should affect grass, particles, and cloth too.
     
    Last edited: Jul 25, 2011
  20. AnomalusUndrdog

    AnomalusUndrdog

    Joined:
    Jul 3, 2009
    Posts:
    1,409
    This doesn't work in a web build. Perhaps System.Reflection is not included in the web build subset of the mono runtime?
     
  21. Waz

    Waz

    Joined:
    May 1, 2010
    Posts:
    245
    URL? I don't see it, still in 3.4.0f5.
     
  22. PEF

    PEF

    Joined:
    Mar 5, 2012
    Posts:
    6
    Hi Nividica, I followed both your scripts and tried to apply them to my environment which has a windzone which affects the grass and trees however I have encountered some problems when attaching them to my camera and the windzone object in my environment. The errors that appear on the console are the following which I have posted below. If you can aid me with this I'll be most grateful. Thanks.

    1. The starting settings of the windzone are :Main=1, Turbulence=1, Pulse Magnitude=0.5, Pulse Frequency=0.01 UnityEngine.Debug:Log(Object)

    2. IndexOutOfRangeException: Array index is out of range. (wrapper stelemref) object:stelemrf (object,intptr,object)

    3. NullReferenceException: Object reference not set to an instance of an object
    ScriptableWindzoneInterface.GetWindZoneValue (System.String MemberName) (at Assets/Standard Assets (Mobile)/Scripts/ScriptableWindzoneInterface.cs:150)
    ScriptableWindzoneInterface.get_WindMain () (at Assets/Standard Assets (Mobile)/Scripts/ScriptableWindzoneInterface.cs:45)
    WindzoneController.Start () (at Assets/Standard Assets (Mobile)/Scripts/WindzoneController.cs:16)

    4. Could not find a wind zone to link to: Main Camera (WindzoneController)
    UnityEngine.Debug:LogError(Object)
    ScriptableWindzoneInterface:Init() (at Assets/Standard Assets (Mobile)/Scripts/ScriptableWindzoneInterface.cs:120)
    WindzoneController:Start() (at Assets/Standard Assets (Mobile)/Scripts/WindzoneController.cs:13)
     
  23. Nividica

    Nividica

    Joined:
    May 19, 2011
    Posts:
    11

    Hmm, it's been a while since I last worked with this, but from log#4, it looks like the WindZoneController.cs is not attached to an object that also has a windzone. The object you attached WindZoneController.cs to must also have a windzone component attached, as the reference to the windzone is acquired via the parent object.
    -------------------------------------------------------
    Like:
    [Object]
    +[Attached][Windzone]
    +[Attached][WindZoneController.cs]
    ------------------------
    Not:
    [Object1]
    +[Attached][Windzone]

    [Object2]
    +[Attached][WindZoneController.cs]
    -------------------------------------------------------

    Also, each WindZoneController.cs controls it's own windzone, the script is not global, so you cant have something like this:
    -------------------------------------------------------
    [Object]
    +[Attached][Windzone]
    +[Attached][WindZoneController.cs]

    [Camera]
    +[Attached][WindZoneController.cs]
    -------------------------------------------------------
    Making any changes to Camera.WindZoneController would have no effect on Object.Windzone, and in-fact I think it would report errors, as the camera does not have an attached windzone.


    The possible issues I can think of are:
    1) WindZoneController.cs is not attached to an object with an attached WindZone
    2) The version of unity your using no longer supports my solution ( I'm running version 3.3.0f4 )
    3) Your building for a platform that doesn't support introspection. ( The web version does not )

    Let me know if this helps any :)
     
  24. PEF

    PEF

    Joined:
    Mar 5, 2012
    Posts:
    6
    Hi Nividica, thanks for your quick response however I'm still having problems. I have attached both the ScriptableWindzoneInterface and WindzoneController scripts to my terrain and thats the only place where script is added not even the camera have the scripts attached or even the trees and grass because its part of the terrain. I also wanted to ask do these scripts allow me to change the values of the windzone from the script itself? because even though there is interaction from the grass and tress from the windzone I'm trying to control the windzone to make dynamic wind as in constant changing wind and if that isn't possible then changing the values of the windzone values via script would be good. The following errors I'm getting are

    1. Could not find a wind zone to link to: Terrain (WindzoneController)
    UnityEngine.Debug:LogError(Object)
    ScriptableWindzoneInterface:Init() (at Assets/Standard Assets (Mobile)/Scripts/ScriptableWindzoneInterface.cs:120)
    WindzoneController:Start() (at Assets/Standard Assets (Mobile)/Scripts/WindzoneController.cs:13)

    2. NullReferenceException: Object reference not set to an instance of an object
    ScriptableWindzoneInterface.GetWindZoneValue (System.String MemberName) (at Assets/Standard Assets (Mobile)/Scripts/ScriptableWindzoneInterface.cs:150)
    ScriptableWindzoneInterface.get_WindMain () (at Assets/Standard Assets (Mobile)/Scripts/ScriptableWindzoneInterface.cs:45)
    WindzoneController.Start () (at Assets/Standard Assets (Mobile)/Scripts/WindzoneController.cs:16)

    Thanks for reading this, sorry if I wrote too much
     
    Last edited: Mar 8, 2012
  25. Nividica

    Nividica

    Joined:
    May 19, 2011
    Posts:
    11
    Hey PEF, ment to get back sooner but I've had my head wrapped up in writing code for minecraft :D
    When I get back home I'll take a closer look and see if there is something I'm overlooking, and I'll post some pics of my setup so u can compare.
     
  26. Nividica

    Nividica

    Joined:
    May 19, 2011
    Posts:
    11
    Hmm, it's still not finding a Windzone to link to. It's hard to say where the problem lies since I can't see the project layout. But no worries, I whiped up a quick example project for you so you can see first hand how I'm doing it. If throws errors with my example project then I would have to guess there is an incompatibility somewhere, version, platform ect.

    Yup, the script publicly exposes all the values of the windzone except the mode.

    • WindMain
    • WindTurbulence
    • WindPulseMagnitude
    • WindPulseFrequency
    • Radius
    View attachment $WindzoneExample.zip
     
  27. PEF

    PEF

    Joined:
    Mar 5, 2012
    Posts:
    6
    Hey Nividica, thanks for the example it was good to see your layout and your example worked without any errors however I have applied the windzonecontroller to the windzone in my environment however I am still encountering 1 error that keeps re-occuring which I have pasted below. I have provided some screenshots of my environment along with the layout. If you wouldn't mind looking at them also in the script you mentioned the wind can be controlled. So do I change the value in the Windzonecontroller script where it says

    WindMain

    WindTurbulence

    WindPulseMagnitude

    WindPulseFrequency

    Radius



    1. IndexOutOfRangeException: Array index is out of range.
    (wrapper stelemref) object:stelemref (object,intptr,object)
    ScriptableWindzoneInterface.set_WindMain (Single value) (at Assets/Standard Assets (Mobile)/Scripts/ScriptableWindzoneInterface.cs:50)
    WindzoneController.Update () (at Assets/Standard Assets (Mobile)/Scripts/WindzoneController.cs:26)
     

    Attached Files:

  28. Nividica

    Nividica

    Joined:
    May 19, 2011
    Posts:
    11
    It looks like the line it's talking about is
    Code (csharp):
    1.  
    2. set
    3.             {
    4.                 // Set the argument
    5. --------------->m_WindZoneArgs[0] = value ;
    6.                
    7.                 // Set the value of `windMain`
    8.                 SetWindZoneValue( "set_windMain" , m_WindZoneArgs ) ;
    9.             }
    10.  
    Not sure why it would single that one out, just make sure that line still has a 0 in it.

    The m_WindZoneArgs should be getting initialized during the objects creation via:
    Code (csharp):
    1.  
    2. // Used to pass an argument to WindZone setter functions
    3.         object[] m_WindZoneArgs = new object[1] ;
    4.  
    However it may not be, try re-initializing it in the Init() function like this:
    Code (csharp):
    1.  
    2.  public void Init () {
    3.            
    4.             // Get the windzone of this game object
    5.             m_WindzoneComponent = GetComponent("WindZone");
    6.            
    7.             // Ensure there was a windzone to link to
    8.             if ( m_WindzoneComponent == null ) {
    9.                 // Log the error
    10.                 Debug.LogError( "Could not find a wind zone to link to: " + this ) ;
    11.                
    12.                 // Disable this script for the remainder of the run
    13.                 this.enabled = false;
    14.                
    15.                 // Stop here
    16.                 return ;
    17.             }            
    18.  
    19.             // Re-initialize the argument array
    20.             m_WindZoneArgs = new object[1] ;          
    21.  
    22.             // Get the system qualified type
    23.             m_WindzoneType = m_WindzoneComponent.GetType() ;
    24.            
    25.         }
    26.  
    I just wish the line number in the errors lined up better with the actual script, it's one of those things about unity that's bugged me for a long time.

    Sure, just treat it like any other class's properties. You can use Update() to check the state game to update and adjust the wind accordingly, or you can use a more event driven approach, like creating a button in the GUI that stops the wind. It all depends on how you want your system set up. If your just looking for some randomness to your wind putting the logic in Update() will work just fine.
     
  29. PEF

    PEF

    Joined:
    Mar 5, 2012
    Posts:
    6
    Hey Nividica, thanks for your help and there are no errors. However even after your explanation on how to the change the values of the windzone from the script itself I am still not certain. In the WindzoneController script I can see WindMain, WindTurbulence, WindPulseMagnitude, WindPulseFrequency and Radius but my confusion lies because there are no values to change as in terms of numbers. Instead it will say WindTurbulence = WindMain ; but in Unity the default settings are displayed 1 or 0.01. If you have time could you get back to me on this one? Thanks.
     
  30. Nividica

    Nividica

    Joined:
    May 19, 2011
    Posts:
    11
    OH, You mean in the example script! Yeah I was setting all the values to the same number in the example to make sure everything was working as it should. That script is there as an example of how to create a child class of ScriptableWindzoneInterface, you can use it or create a new child class with this template:
    Code (csharp):
    1.  
    2.     using UnityEngine;
    3.     using System.Collections;
    4.      
    5.     public class <YOURCLASSNAMEHERE> : ScriptableWindzoneInterface {
    6.      
    7.         // Use this for initialization
    8.         void Start () {
    9.             // Tell the ScriptableWindzoneInterface to initialize
    10.             base.Init() ;
    11.         }
    12.     }
    13.  
    For example if you wanted to make a windzone that responded to a change in the seasons you could do something like this:
    Code (csharp):
    1.     using UnityEngine;
    2.     using System.Collections;
    3.      
    4.     public class NorthernJetStream : ScriptableWindzoneInterface {
    5.      
    6.         // Use this for initialization
    7.         void Start () {
    8.             // Tell the ScriptableWindzoneInterface to initialize
    9.             base.Init() ;
    10.            
    11.             // Set the intial values
    12.             WindMain = 1.0f;
    13.             WindTurbulence = 2.0f;
    14.             WindPulseMagnitude = 3.0f;
    15.             WindPulseFrequency = 4.0f;
    16.     }
    17.        
    18.         // Update is called once per frame
    19.         void Update () {
    20.             // Its autumn or spring make the wind erratic
    21.             if( TheSeason.isAutumn() || TheSeason.isSpring() ) {
    22.                 WindMain = Random.Range( 0.0f , 15.0f );
    23.             } else {
    24.                 WindMain = 1.0f;
    25.             }
    26.         }
    27.     }
    Or like this example that sets the windzone values when the script starts, and then spins the windzone like a floor fan.
    Code (csharp):
    1.     using UnityEngine;
    2.     using System.Collections;    
    3.     public class SpinningFan : ScriptableWindzoneInterface {
    4.         void Start () {
    5.             // Tell the ScriptableWindzoneInterface to initialize
    6.             base.Init() ;
    7.            
    8.             // Set the intilial values
    9.             WindMain = System.DateTime.Now.Second;
    10.             WindTurbulence = 0.1f ;
    11.             WindPulseMagnitude = 0.5f ;
    12.             WindPulseFrequency = 0.2f ;
    13.          }
    14.      
    15.         // Update is called once per frame
    16.         void Update () {
    17.             this.transform.Rotate( Vector3.up , 1.0f );
    18.         }
    19.     }
    20.  
    21.        
     
  31. PEF

    PEF

    Joined:
    Mar 5, 2012
    Posts:
    6
    Hey Nividica, thanks for the replies. The windzone example which makes the wind erractic depending on the seasons seems like a good option but I have no clue on how to create seasons in Unity. Do you have an idea on how to make this work? Another thing is with the Wind settings in the WinzoneController what does this line do exactly WindMain = Mathf.PingPong( ( Time.time / 2.0F ) , 1.0F ) ; and if I wanted to change the wind values could I use your WindzoneController example and write somethin like this for the wind values?

    WindMain = 1.0f

    WindTurbulence = 1.0f ;

    WindPulseMagnitude = 2.0f ;

    WindPulseFrequency = 3.0f ;

    Radius = 20f;
     
  32. Nividica

    Nividica

    Joined:
    May 19, 2011
    Posts:
    11
    Not really ;) Just sounds like a good idea.

    The script reference says:
    Code (csharp):
    1. PingPongs the value t, so that it is never larger than length and never smaller than 0.
    2. The returned value will move back and forth between 0 and length.
    How it interacts with my code is that each time Update() is called it adjusts the value of WindMain from 0->1.0 then 1.0->0 (hence ping-pong), the divide by 2 just slows down the rate at which this happens. It is in the example so that you can verify that the script is running and that the values are being adjusted during a test-play(via the inspector)

    Yup.
     
  33. PEF

    PEF

    Joined:
    Mar 5, 2012
    Posts:
    6
    Hey Nividica, thanks for your quick response yet again. I still have a few questions to ask though I am using your WindzoneController example and when I write these values which I have pasted below. The settings are still the default settings on the actual Windzone inside Unity and the console still displays the current settings of the Windzone inside Unity. So how would I get the Windzone to display the values I entered in the script and is there a way to make the wind random without having to use the season example you showed me? My aim is to make the wind dynamic via script or where I can change the values and those values affect the Windzone.

    WindMain = Mathf.PingPong( ( Time.time / 2.0F ) , 1.0F ) ;

    WindTurbulence = 1.0f ;

    WindPulseMagnitude = 2.0f ;

    WindPulseFrequency = 3.0f ;

    Radius = 20f;
     
    Last edited: Mar 16, 2012
  34. MFen

    MFen

    Joined:
    Sep 25, 2013
    Posts:
    13
    myTerrain.terrainData.wavingGrassSpeed = 0;
    myTerrain.terrainData.wavingGrassAmount = 0;
    myTerrain.terrainData.wavingGrassStrength = 0;

    These are for the wind settings found in the terraindata.
     
  35. mostlyhuman

    mostlyhuman

    Joined:
    Mar 16, 2013
    Posts:
    20
    Has anything changed over the years with the wind zones to make all of this easier?