Search Unity

  1. We are looking for your feedback about Templates! Tell us about your experiences by taking our survey.
    Dismiss Notice
  2. Curious about what's going to be in 2021.1? Have a look at the 2021.1 beta blog post.
    Dismiss Notice
  3. Want to see 2021.1b in action? Sign up for our 2021.1 Beta Webinar on February 25 for a live presentation and a Q&A session with guests from R&D.
    Dismiss Notice

2D: Buoyancy Effector with Custom gravity vector

Discussion in '5.3 Beta' started by AVOlight, Oct 16, 2015.

  1. AVOlight

    AVOlight

    Joined:
    Apr 15, 2014
    Posts:
    421
    if i could bypass the gravity vector with my own, this component would have even more applications :)

    maybe by pairing it with a Area Force 2D component as source gravity
    thinking about it now this is much more complicated then i originally thought
     
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    3,340
    The effector specifying gravity makes things much more complex. Firstly it adds a couple of properties (an option to disable world gravity and one to specify the custom gravity). Secondly, the buoyancy force has to act opposite to the gravity force which means the surface has to be a line perpendicular to that vector. Right now, the surface is a plane that extends, in world-space, along the x-axis to infinity. This makes it fast (for clipping) and simple and covers the common usage case.

    Maybe if you can elaborate on the many other applications you're referring to, there might be ways to do it now or that could be considered for the future. All feedback is most welcome.

    EDIT: I'm guessing but if you're looking for something that pushes an object out of a collider in a controlled direction then the PointEffector2D can do that.
     
    Last edited: Oct 16, 2015
  3. AVOlight

    AVOlight

    Joined:
    Apr 15, 2014
    Posts:
    421
    thank you for taking the time :)
    not many but more than currently available
    probably not practical considering performance
    buoyancy from any direction is really just fun stuff for level design like
    radial buoyancy and curve buoyancy would be pretty cool to play with
    maybe sometime after the 2D smartsprite is done
    i fully understand that an idea is really nothing compared to implementing an idea
     
  4. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    3,340
    There's a bunch of improvements planned for the buoyancy stuff so watch this space!
     
    MrEsquire and AVOlight like this.
  5. jeffweber

    jeffweber

    Joined:
    Dec 17, 2009
    Posts:
    601
    Would support for dynamic surface ( waves ) be one of these improvements by any chance?

    -Jeff
     
    johanneskopf likes this.
  6. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    3,340
    Indeed I would like to get this as an option but it does add a certain complexity to the calculations. The surface would need some strict constraints:
    • Surface is still defined by the surface level
    • Surface points in X are X-axis offsets along the surface level
    • Surface points in Y are Y-axis offset above/below the surface level
    • Outside the supplied points in X, the surface level is used (assumes a Y offset of zero)
    Code (CSharp):
    1. Vector2[] points = { ... };
    2. surfaceEffector.surface = points;
    This would allow you to specify an array of points where each point defines an offset along and up/down the surface (see the attached image).

    The red arrows define a point offsetting from the surface level to define the surface indicated in yellow. The surface clipping would then be done against the yellow line. Anything outside of the points would just be against the surface level.

    You'd be free to change this each fixed-update with no performance overhead as we'd not need to perform any complex checking of the points provided as they're just offsets from the surface.

    This obviously isn't guarantee of how it'd work, really just to open a discussion around it.
     

    Attached Files:

    johanneskopf likes this.
  7. jeffweber

    jeffweber

    Joined:
    Dec 17, 2009
    Posts:
    601
    This is sounding pretty good, but could you re-explain this:

    By outside the points, do you mean to the right or left of the points that have the offsets?

    So if a block were "floating" on the surface defined by the yellow line, buoyancy forces would only get applied to the parts of the block beneath the yellow line, correct?

    If so, this would work perfect for my needs.

    -Jeff

    BTW, here is what my current game looks like with my custom 2D water system. Would love to swap out the custom stuff for built in unity functionality when it's available.
     
    johanneskopf likes this.
  8. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    3,340
    Yes, anything outside of the points you define (along the X-axis). It could even be an option to only use the X-axis range you specify and ignore any buoyancy beyond that.

    I'm also wondering if it would be better to be able to specify the number of points in the X-axis in the effector? We could set the point count, spacing and x-axis offset. This would give you a span of equally spaced points and you would only have to supply an array of Y offsets (array of floats) which provides some added benefits:
    • Much quicker, less data, no need for sorting the X-axis offsets.
    • You would be allowed to read/write individual points rather than having to read/write the whole array.
    • You could have a gizmo that allowed you to drag the points up/down in the scene.
    • You could have more points than you show on screen and simply adjust the 'surfaceOffset' to make the surface move left/right (thinking waves moving left/right without having to modify the surface).
    • Possible to allow 'wrapping' of the points provided out to infinity (thinking of a wave surface that repeats infinitely)
    Code (CSharp):
    1. // Surface is 100 points, no offset but equally spaced by 0.25 each.
    2. buoyancy.surfaceCount = 100;
    3. buoyancy.surfaceOffset = 0.0f;
    4. buoyancy.surfaceSpacing = 0.25f;
    5.  
    6. // Access whole surface offset array.
    7. float[100] surfaceOffsets = { ... };
    8. buoyancy.surface = surfaceOffsets ;
    9.  
    10. // Access individual surface offsets.
    11. for (var i = 0; i < 100; ++i)
    12.    buoyancy.setSurfaceOffset (i, surfaceOffset[i]);
    13.  
    14. // Set the whole surface level up/down.
    15. buoyancy.surfaceLevel = 5.0f;
    Nothing is written in stone, feedback welcome.
     
    Last edited: Nov 5, 2015
    johanneskopf and mh114 like this.
  9. jeffweber

    jeffweber

    Joined:
    Dec 17, 2009
    Posts:
    601
    I'm completely fine with this suggestion. My current setup uses equally spaced points along the X-axis and my wave algorithm simply adjusts them up and down.

    I can't really see a need to have the x-positions non-equally spaced so I think it'd be worth the benefits you list.

    -Jeff
     
    MelvMay likes this.
unityunity