From 57088cfd120936ecf3eaf833bb4873db55104d3c Mon Sep 17 00:00:00 2001 From: Antoine H Date: Mon, 28 Dec 2020 10:52:50 +0100 Subject: [PATCH] Encapsulation movement Tavernkeeper_controller --- Assets/Scripts/Tavernkeeper_controller.cs | 25 ++++++++++++++--------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/Assets/Scripts/Tavernkeeper_controller.cs b/Assets/Scripts/Tavernkeeper_controller.cs index 94a5363..a1ee684 100644 --- a/Assets/Scripts/Tavernkeeper_controller.cs +++ b/Assets/Scripts/Tavernkeeper_controller.cs @@ -79,16 +79,7 @@ public class Tavernkeeper_controller : MonoBehaviour hands = Input.GetAxis("Hand"); //Movement action - Vector2 move = new Vector2(horizontal, vertical); - //Update animation direction - if(!Mathf.Approximately(move.x, 0.0f) || !Mathf.Approximately(move.y, 0.0f)) //Movement requested ? - { - lookDirection.Set(move.x, move.y); //== lookDirection=move - lookDirection.Normalize(); - } - animator.SetFloat("Look X", lookDirection.x); - animator.SetFloat("Look Y", lookDirection.y); - animator.SetFloat("Speed", move.magnitude); + movement(new Vector2(horizontal, vertical)); //Actions delay if(isInteracting) @@ -121,6 +112,20 @@ public class Tavernkeeper_controller : MonoBehaviour rigidbody2d.MovePosition(position); //Movement processed by the phyisc engine for Collision, etc. } + //Movement + void movement(Vector2 move) + { + //Update animation direction + if(!Mathf.Approximately(move.x, 0.0f) || !Mathf.Approximately(move.y, 0.0f)) //Movement requested ? + { + lookDirection.Set(move.x, move.y); //== lookDirection=move + lookDirection.Normalize(); + } + animator.SetFloat("Look X", lookDirection.x); + animator.SetFloat("Look Y", lookDirection.y); + animator.SetFloat("Speed", move.magnitude); + } + //Handle action with hands ("left" or "right") void handAction(string hand) {