- 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(WaterController 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.9f;
- rb.velocity = dragVel;
-
- }
-
- public override void OnWaterEnter(WaterController water) {
- //rb.drag = 1;
- }
-
- public override void OnWaterExit(WaterController water) {
- // rb.drag = airDrag;
- }
-
- public virtual IEnumerator pushObject(Vector3 point,float power, float totalTime) {
- Vector3 dir = transform.position - point;
- dir = Vector3.ProjectOnPlane(dir, Vector3.up);
- dir.Normalize();
-
- float elapsedTime = 0;
-
- while (elapsedTime < totalTime) {
-
- Vector3 force = dir * power * Time.deltaTime;
- rb.AddForce(force);
-
- yield return new WaitForEndOfFrame();
-
- elapsedTime += Time.deltaTime;
- }
- }
-
-
- /// <summary>
- ///
- /// </summary>
- public void BuoyancyCalc() {
-
-
-
-
-
- }
-
-
-
-
- }
|