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.
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
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.
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 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.
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
Wow, amazing.I'm currently learning water shader and this make my water more realistic
Simple yet effective! Thanks for some great ideas
Gold, Nothing more to say
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.
Very cool - thank you
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;
}
}
thanks
gave me a million errors
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
Thank you, the tutorial helped a lot!
Really thanks, i needed help with that!
Thank you bro!
great video ! thanks
subscribed cus you rock!
Thank you
I am getting error , any solution...
IndexOutOfRangeException: Index was outside the bounds of the array.
Thank you!
Is there a link for the project please?
thanks man
👍
🔥🔥🔥
Goodgoodgoood!
Thank you!!!!!!
help, the rigid body just falls right through the plane, are you suppsoed to add something to the plane aka waterR??
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.
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;
@@shani1328 what would you do if you want multiple water planes in a scene that have different heights?
@@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.
you should make a link to have the code
why do you make public floats instead of serializing private floats? Just curious
faster to type
Noice
how is your sky that color?
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
Hi, yeah I explain it in the part 2, it should be up in a few days !
@@vincentaindiedev Great, cool :) thanks
the object does not float for me :(
change "if(difference < 0)" to a different number, for me 1 works.
can someone help me my shipS all flip over
or just fly up
Can u plsssssssssssssssssssssssssss give a link for the project?
Thank you
Can u plsssssssssssssssssssssssssss give a link for the project?
Can u plsssssssssssssssssssssssssss give a link for the project?