Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Accessing External Force (Wind)

Discussion in 'Scripting' started by sfaok, Apr 18, 2014.

  1. sfaok

    sfaok

    Joined:
    Nov 27, 2012
    Posts:
    23
    I'm using a WindZone to simulate particles moving in an ocean current (via activating Shuriken External Forces). The effect is fantastic but I want to hook it up to my vegetation system so that they are in sync (currently they are affected by a different wind force).

    Is there a way of accessing the external force vector via script?
     
  2. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,513
    WindZone is a protected class that Unity doesn't give you script access to.

    You can get a reference to the component by looping over all the components and using reflection to find the correct object. Then use reflection to access it.

    Just note... you'll be flying blind, there's no documentation, and you'll have to sit there for a while writing code to just rip apart and reflect all the aspects of it and then guess at what each thing is.

    Then worst... once you have that all done. If Unity changes the shape of the class in the future... your system will break. Which means you'll be stuck on whatever version of unity is just before that breaking change.



    I'm not sure what vegetation system you use. But I know unity has a tree system that works with the WindZone:

    http://docs.unity3d.com/Documentation/Components/class-Tree.html
     
  3. Hikiko66

    Hikiko66

    Joined:
    May 5, 2013
    Posts:
    1,304
    Last edited: Apr 18, 2014
  4. sfaok

    sfaok

    Joined:
    Nov 27, 2012
    Posts:
    23
    I'm using ATS Mobile Foliage because Unity's system isn't great for underwater plants.

    Unfortunately it seems that while I can access all the properties of a WindZone using the reflection method (WindMain, WindTurbulence, WindPulseMagnitude, WindPulseFrequency, WindRadius) these are just the float parameters - none of these change during runtime. The actual external force it generates is still not visible.
     
  5. Hikiko66

    Hikiko66

    Joined:
    May 5, 2013
    Posts:
    1,304
    I don't think external force changes (unless you change the windzone settings), far more likely your particle system has other forces being applied as well.
     
    Last edited: Apr 19, 2014
  6. sfaok

    sfaok

    Joined:
    Nov 27, 2012
    Posts:
    23
    By varying the parameters of a windzone I can produce all kinds of nice pulsing effects, the only other force on the particles is (dampened) gravity. The turbulence parameter is very important for example. However as I don't know what formula is used to turn the params into a force, and we don't seem to have a way of acessing the external force directly I can't apply it to the vegatation shaders. Really annoying!