From d439d7dce5935ac6e9e3a6928e6a3fe199e70ae2 Mon Sep 17 00:00:00 2001 From: Patrice Vignola Date: Sat, 22 Aug 2015 10:08:59 -0400 Subject: [PATCH] Add a temporary "push" method for when the player will get knocked back by a pillow --- Assets/Scripts/Child.cs | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/Assets/Scripts/Child.cs b/Assets/Scripts/Child.cs index a485243..39ccabf 100644 --- a/Assets/Scripts/Child.cs +++ b/Assets/Scripts/Child.cs @@ -21,6 +21,7 @@ public class Child : MonoBehaviour public Transform target; private int _index; + private bool _isPushed = false; public int Index { @@ -72,16 +73,26 @@ public class Child : MonoBehaviour { // We move the child depending on the camera orientation - Vector3 forwardDir = Camera.main.transform.forward; - Vector3 rightDir = Camera.main.transform.right; + if (_isPushed) + { + if (_rb.velocity == Vector3.zero) + { + _isPushed = false; + } + } + else + { + Vector3 forwardDir = Camera.main.transform.forward; + Vector3 rightDir = Camera.main.transform.right; - forwardDir *= _zValue * Speed; - forwardDir.y = _rb.velocity.y; + forwardDir *= _zValue * Speed; + forwardDir.y = _rb.velocity.y; - rightDir *= _xValue * Speed; - rightDir.y = 0f; + rightDir *= _xValue * Speed; + rightDir.y = 0f; - _rb.velocity = forwardDir + rightDir; + _rb.velocity = forwardDir + rightDir; + } } private bool IsGrounded() @@ -168,6 +179,12 @@ public class Child : MonoBehaviour } } + public void Push(Vector3 force) + { + _isPushed = true; + _rb.AddForce(force); + } + private void TakeLavaDamage() { // TODO: Lose a life (probably) and become immune for ~ 2 or 3 seconds