diff --git a/Assets/Prefabs/Child.prefab b/Assets/Prefabs/Child.prefab index beacf7f..dd17061 100644 Binary files a/Assets/Prefabs/Child.prefab and b/Assets/Prefabs/Child.prefab differ diff --git a/Assets/Prefabs/InputManager.prefab b/Assets/Prefabs/InputManager.prefab index d58fb1d..6ad8534 100644 Binary files a/Assets/Prefabs/InputManager.prefab and b/Assets/Prefabs/InputManager.prefab differ diff --git a/Assets/Scenes/PatScene.unity b/Assets/Scenes/PatScene.unity index bcf66ca..48c68cf 100644 Binary files a/Assets/Scenes/PatScene.unity and b/Assets/Scenes/PatScene.unity differ diff --git a/Assets/Scripts/Child.cs b/Assets/Scripts/Child.cs index 9ff814d..cf312a4 100644 --- a/Assets/Scripts/Child.cs +++ b/Assets/Scripts/Child.cs @@ -5,27 +5,62 @@ using System.Collections; public class Child : MonoBehaviour { public float Speed = 10f; + public float JumpForce = 10f; + public GameObject GroundCheck; private Rigidbody _rb; + private bool _isGrounded = false; + private float _xValue; + private float _zValue; void Awake() { _rb = GetComponent(); } - public void Move(float xValue, float zValue) + void Update() + { + _isGrounded = IsGrounded(); + + Debug.Log(_isGrounded); + } + + void FixedUpdate() { // We move the child depending on the camera orientation Vector3 forwardDir = Camera.main.transform.forward; Vector3 rightDir = Camera.main.transform.right; - forwardDir.y = 0f; - forwardDir *= zValue * Speed; + forwardDir *= _zValue * Speed; + forwardDir.y = _rb.velocity.y; + rightDir *= _xValue * Speed; rightDir.y = 0f; - rightDir *= xValue * Speed; _rb.velocity = forwardDir + rightDir; } + + private bool IsGrounded() + { + Collider[] colliders = Physics.OverlapSphere(GroundCheck.transform.position, 0.5f, 1 << LayerMask.NameToLayer("Ground")); + + return colliders.Length > 0; + } + + public void Move(float xValue, float zValue) + { + _xValue = xValue; + _zValue = zValue; + } + + public void Jump() + { + if (_isGrounded) + { + _isGrounded = false; + + _rb.AddForce(new Vector3(0f, JumpForce, 0f)); + } + } } diff --git a/Assets/Scripts/ChildController.cs b/Assets/Scripts/ChildController.cs index cc9a375..54826bf 100644 --- a/Assets/Scripts/ChildController.cs +++ b/Assets/Scripts/ChildController.cs @@ -14,12 +14,13 @@ public class ChildController : MonoBehaviour void Awake() { InputManager.Instance.PushActiveContext("Gameplay", (int)PlayerNumber); - InputManager.Instance.AddCallback((int)PlayerNumber, HandlePlayerInput); + InputManager.Instance.AddCallback((int)PlayerNumber, HandlePlayerAxis); + InputManager.Instance.AddCallback((int)PlayerNumber, HandlePlayerButtons); _child = GetComponent(); } - private void HandlePlayerInput(MappedInput input) + private void HandlePlayerAxis(MappedInput input) { if (this == null) return; @@ -48,4 +49,14 @@ public class ChildController : MonoBehaviour _child.Move(xValue, zValue); } + private void HandlePlayerButtons(MappedInput input) + { + if (this == null) return; + + if (input.Actions.Contains("Jump")) + { + _child.Jump(); + } + } + } diff --git a/ProjectSettings/TagManager.asset b/ProjectSettings/TagManager.asset index d015127..c5fdf55 100644 Binary files a/ProjectSettings/TagManager.asset and b/ProjectSettings/TagManager.asset differ