diff --git a/IronToad_UnityProject/Assets/Scripts/BoatController.cs b/IronToad_UnityProject/Assets/Scripts/BoatController.cs index e381ce8..34d2718 100644 --- a/IronToad_UnityProject/Assets/Scripts/BoatController.cs +++ b/IronToad_UnityProject/Assets/Scripts/BoatController.cs @@ -7,6 +7,10 @@ public class BoatController : BuoyantObject { public float trunSpeed = 0.5f; public float breakSpeed = 20f; + [Range(0.8f,1)] + public float stopRatio = 0.95f; + + private bool applyBreak = true; // Use this for initialization void Start() { @@ -17,6 +21,10 @@ public class BoatController : BuoyantObject { lookAtDir(Vector3.ProjectOnPlane(rb.velocity, Vector3.up)); } + void FixedUpdate() { + + doBreak(); + } // Update is called once per frame void lookAtDir(Vector3 inputDir) { @@ -38,4 +46,42 @@ public class BoatController : BuoyantObject { } + private void doBreak() { + if (!applyBreak) + return; + + Vector3 vel = rb.velocity; + Vector3 flatVel = Vector3.ProjectOnPlane(vel, Vector3.up); + + flatVel *= stopRatio; + flatVel.y = vel.y; + rb.velocity = flatVel; + } + + public override IEnumerator pushObject(Vector3 point, float power, float totalTime) { + Vector3 dir = transform.position - point; + dir = Vector3.ProjectOnPlane(dir, Vector3.up); + dir.Normalize(); + + float elapsedTime = 0; + + Vector3 force = dir * power; + rb.AddForce(force,ForceMode.Impulse); + + while (elapsedTime < totalTime) { + applyBreak = false; + + force = dir * power * Time.deltaTime; + rb.AddForce(force); + + yield return new WaitForEndOfFrame(); + + elapsedTime += Time.deltaTime; + } + applyBreak = true; + } + + + + } diff --git a/IronToad_UnityProject/Assets/Scripts/DontRotate.cs b/IronToad_UnityProject/Assets/Scripts/DontRotate.cs index 584f172..1ef8c6f 100644 --- a/IronToad_UnityProject/Assets/Scripts/DontRotate.cs +++ b/IronToad_UnityProject/Assets/Scripts/DontRotate.cs @@ -5,6 +5,11 @@ using UnityEngine; public class DontRotate : MonoBehaviour { private Quaternion originalRot; + + public float maxAngle; + + public float turnSpeed = 0.5f; + // Use this for initialization void Start () { originalRot = transform.rotation; @@ -14,4 +19,11 @@ public class DontRotate : MonoBehaviour { void Update () { transform.rotation = originalRot; } + + // Update is called once per frame + void lookAtDir(Vector3 inputDir) { + Quaternion targetRotation = Quaternion.LookRotation(inputDir, Vector3.up); + float str = Mathf.Min(turnSpeed * Time.deltaTime, 1); + transform.rotation = Quaternion.Lerp(transform.rotation, targetRotation, str); + } }