Click here to Skip to main content
15,887,350 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering.HighDefinition;

public class Floating : MonoBehaviour
{
    public Rigidbody rb;
    public float depthBefSub;
    public float displacementAnt;
    public int floaters;
    public float waterOrag;
    public float waterAngularOrag;
    public WaterSurface water;
    WaterSearchParameters Search;
    WaterSearchResult SearchResult;

    private void FixedUpdate()
    {
        rb.AddForceAtPosition(Physics.gravity / floaters, transform.position, ForceMode.Acceleration);

        Search.startPosition = transform.position;

        water.FindWaterSurfaceHeight(Search, out SearchResult);

        if (transform.position.y < SearchResult.height)
        {
            float displacementMulti = Mathf.Clamp01(SearchResult.height - transform.position.y / depthBefSub) * displacementAnt;
            rb.AddForceAtPosition(new Vector3(0f, Mathf.Abs(Physics.gravity.y) * displacementMulti, 0f), transform.position, ForceMode.Acceleration);
            rb.AddForce(displacementMulti * -rb.velocity * waterOrag * Time.fixedDeltaTime, ForceMode.VelocityChange);
            rb.AddForce(displacementMulti * -rb.angularVelocity * waterAngularOrag * Time.fixedDeltaTime, ForceMode.VelocityChange);
        }
    }
}


What I have tried:

nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
Posted
Updated 2-Jul-23 15:48pm
Comments
[no name] 1-Jul-23 20:46pm    
Use it as a multiplier from the "standard" case: sea level. Then vary the parameters you're interested in by their corresponding multiplier: depth vs pressure; drag vs speed; etc. If you're not moving, drag isn't relevant.
Richard Deeming 5-Jul-23 4:43am    
Rather than explaining the problem, and telling us what you have tried and where you are stuck, you have simply dumped your code, and then hammered the "n" key enough times to circumvent the minimum length requirements on the "what I have tried" section.

That is not a good question.

1 solution

Best place to ask Unity questions is here: Unity Support Forums[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900