Buoyancy with Unity Rigidbodies - Part 1 / Planar Buoyancy

Поделиться
HTML-код
  • Опубликовано: 19 сен 2024

Комментарии • 43

  • @LostAngel175
    @LostAngel175 2 месяца назад

    Wow, amazing.I'm currently learning water shader and this make my water more realistic

  • @dlgcreations2162
    @dlgcreations2162 8 месяцев назад

    Simple yet effective! Thanks for some great ideas

  • @oscarcerro3816
    @oscarcerro3816 3 года назад +1

    Gold, Nothing more to say

  • @gamedevinspire
    @gamedevinspire 2 года назад +1

    so much thanks for these tutorials,however i didnt really need it becausei have my own solution but i thank you agian for creating these tuts for more people out there,you deserve more subscribers and views.

  • @GrevMivlos
    @GrevMivlos 3 года назад +1

    Very cool - thank you

  • @kyle789XBL
    @kyle789XBL 2 года назад +52

    public Transform[] Floaters;
    public float UnderWaterDrag = 3f;
    public float UnderWaterAngularDrag = 1f;
    public float AirDrag = 0f;
    public float AirAngularDrag = 0.05f;
    public float FloatingPower = 15f;
    public float WaterHeight = 0f;
    Rigidbody Rb;
    bool Underwater;
    int FloatersUnderWater;
    // Start is called before the first frame update
    void Start()
    {
    Rb = this.GetComponent();
    }
    // Update is called once per frame
    void FixedUpdate()
    {
    FloatersUnderWater = 0;
    for(int i = 0; i < Floaters.Length; i++)
    {
    float diff = Floaters[i].position.y - WaterHeight;
    if (diff < 0)
    {
    Rb.AddForceAtPosition(Vector3.up * FloatingPower * Mathf.Abs(diff), Floaters[i].position, ForceMode.Force);
    FloatersUnderWater += 1;
    if (!Underwater)
    {
    Underwater = true;
    SwitchState(true);
    }
    }
    }
    if (Underwater && FloatersUnderWater==0)
    {
    Underwater = false;
    SwitchState(false);
    }
    }
    void SwitchState(bool isUnderwater)
    {
    if (isUnderwater)
    {
    Rb.drag = UnderWaterDrag;
    Rb.angularDrag = UnderWaterAngularDrag;
    }
    else
    {
    Rb.drag = AirDrag;
    Rb.angularDrag = AirAngularDrag;
    }
    }

    • @adambuday9011
      @adambuday9011 Год назад

      thanks

    • @JackMayronne
      @JackMayronne Год назад

      gave me a million errors

    • @T.T3.1412
      @T.T3.1412 9 месяцев назад +1

      using System.Collections;
      using System.Collections.Generic;
      using UnityEngine;
      [RequireComponent(typeof(Rigidbody))]
      public class WaterBuoyant : MonoBehaviour
      {

      public Transform[] Floaters;
      public float UnderWaterDrag = 3f;
      public float UnderWaterAngularDrag = 1f;
      public float AirDrag = 0f;
      public float AirAngularDrag = 0.05f;
      public float FloatingPower = 15f;
      public float WaterHeight = 0f;
      Rigidbody Rb;

      int FloatersUnderWater;
      bool Underwater;
      void Start()
      {
      Rb = GetComponent();
      }
      // Update is called once per frame
      void FixedUpdate()
      {
      FloatersUnderWater = 0;
      for(int i = 0; i < Floaters.Length; i++)
      {
      float diff = Floaters[i].position.y - WaterHeight;
      if (diff < 0)
      {
      Rb.AddForceAtPosition(Vector3.up * FloatingPower * Mathf.Abs(diff), Floaters[i].position, ForceMode.Force);
      FloatersUnderWater += 1;
      if (!Underwater)
      {
      Underwater = true;
      SwitchState(true);
      }
      }
      }
      if (Underwater && FloatersUnderWater==0)
      {
      Underwater = false;
      SwitchState(false);
      }
      }
      void SwitchState(bool isUnderwater)
      {
      if (isUnderwater)
      {
      Rb.drag = UnderWaterDrag;
      Rb.angularDrag = UnderWaterAngularDrag;
      }
      else
      {
      Rb.drag = AirDrag;
      Rb.angularDrag = AirAngularDrag;
      }
      }
      }
      try this one it works for me

  • @KJPiGames
    @KJPiGames Год назад

    Thank you, the tutorial helped a lot!

  • @noobissk5761
    @noobissk5761 2 года назад

    Really thanks, i needed help with that!

  • @bajagainsatish4828
    @bajagainsatish4828 8 месяцев назад

    Thank you bro!

  • @ErodonTV
    @ErodonTV 2 года назад

    great video ! thanks

  • @itsukiuehara43
    @itsukiuehara43 2 года назад

    subscribed cus you rock!

  • @mautlej1868
    @mautlej1868 Год назад

    Thank you

  • @abhishekroy7302
    @abhishekroy7302 3 месяца назад

    I am getting error , any solution...
    IndexOutOfRangeException: Index was outside the bounds of the array.

  • @michaelmcveigh9534
    @michaelmcveigh9534 3 года назад

    Thank you!

  • @ItsTommy0
    @ItsTommy0 2 года назад +4

    Is there a link for the project please?

  • @bmazbmaz2342
    @bmazbmaz2342 3 года назад

    thanks man
    👍

  • @Ragwadada
    @Ragwadada 2 года назад

    🔥🔥🔥

  • @uuuuuu2242
    @uuuuuu2242 3 года назад

    Goodgoodgoood!

  • @munyunu
    @munyunu Год назад

    Thank you!!!!!!

  • @shadaialexander1345
    @shadaialexander1345 6 месяцев назад

    help, the rigid body just falls right through the plane, are you suppsoed to add something to the plane aka waterR??

  • @shadowartz9968
    @shadowartz9968 2 года назад +3

    hey really good tutorials, quick question how would i go about limiting the physics to only work when inside the water plane? because ive noticed that moving the plane up or down doesnt change anything about the simulation.

    • @shani1328
      @shani1328 2 года назад +3

      I know this comment if from 5 months ago but just have the water height float be set to the water planes y position. it should be waterHeight = waterPlane.trasform.position.y;

    • @beyond-thenoise
      @beyond-thenoise Год назад

      ​@@shani1328 what would you do if you want multiple water planes in a scene that have different heights?

    • @shani1328
      @shani1328 Год назад

      @@beyond-thenoise Its been a while since I've used / made the buoyancy script, but what I assume you could do is use an array with a for loop for each plane's height.

  • @herdboy83
    @herdboy83 2 года назад +1

    you should make a link to have the code

  • @RavenMinis
    @RavenMinis 3 года назад +1

    why do you make public floats instead of serializing private floats? Just curious

    • @forasago
      @forasago 2 года назад

      faster to type

  • @kairu_b
    @kairu_b 2 года назад

    Noice

  • @catsEeter
    @catsEeter 2 года назад

    how is your sky that color?

  • @OnkAnCa64
    @OnkAnCa64 3 года назад

    Thanks, can you make or do you have an example of a shader made with shader graph on HDRP to manage vertex displacement using a heightmap? thx in advance

    • @vincentaindiedev
      @vincentaindiedev  3 года назад +1

      Hi, yeah I explain it in the part 2, it should be up in a few days !

    • @OnkAnCa64
      @OnkAnCa64 3 года назад

      @@vincentaindiedev Great, cool :) thanks

  • @matus5422
    @matus5422 2 года назад

    the object does not float for me :(

    • @isaacturpin734
      @isaacturpin734 Год назад

      change "if(difference < 0)" to a different number, for me 1 works.

  • @damirshabayev344
    @damirshabayev344 3 года назад

    can someone help me my shipS all flip over

  • @LearnWithArjun
    @LearnWithArjun 2 года назад +1

    Can u plsssssssssssssssssssssssssss give a link for the project?

  • @XieJiJun
    @XieJiJun 3 года назад

    Thank you

  • @LearnWithArjun
    @LearnWithArjun 2 года назад

    Can u plsssssssssssssssssssssssssss give a link for the project?

  • @LearnWithArjun
    @LearnWithArjun 2 года назад

    Can u plsssssssssssssssssssssssssss give a link for the project?