- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
-
- [RequireComponent (typeof(Rigidbody))]
- public class BuoyantObject : WaterObject {
-
-
- [Tooltip ("How fast object will raise into the ")]
- public float BouancyValue = 5;
-
- [Tooltip ("Local point, at which the object floats within the water")]
- public Vector3 BouancyPoint = Vector3.zero;
-
- //rigidbody attached to GameObject
- protected Rigidbody rb;
- private float airDrag;
-
-
- #region Unity Functions
- void Awake() {
-
- rb = GetComponent<Rigidbody>();
- airDrag = rb.drag;
- }
-
- #endregion Unity Functions
-
-
- public override void OnWaterStay(GameObject water,float waveHeight) {
-
- Vector3 waterEntryPoint = transform.position;
- waterEntryPoint.y = water.transform.position.y + waveHeight;
-
- float distance = Vector3.Distance(transform.position + (BouancyPoint * transform.lossyScale.magnitude) , waterEntryPoint);
-
- Vector3 force = Vector3.up * BouancyValue * Mathf.Pow(distance,1.5f);
- if (waterEntryPoint.y < gameObject.transform.position.y + (BouancyPoint.y * transform.lossyScale.y))
- force = Vector3.zero;
-
- rb.AddForce(force);
-
- Vector3 dragVel = rb.velocity;
- dragVel.y *= 0.98f;
- rb.velocity = dragVel;
-
- }
-
- public override void OnWaterEnter(GameObject water) {
- //rb.drag = 1;
- }
-
- public override void OnWaterExit(GameObject water) {
- // rb.drag = airDrag;
- }
-
- /// <summary>
- ///
- /// </summary>
- public void BuoyancyCalc() {
-
-
-
-
-
- }
-
-
-
-
- }
|