Encapsulation movement Tavernkeeper_controller

This commit is contained in:
Antoine H 2020-12-28 10:52:50 +01:00
parent 82e1f258e3
commit 57088cfd12

View file

@ -79,16 +79,7 @@ public class Tavernkeeper_controller : MonoBehaviour
hands = Input.GetAxis("Hand"); hands = Input.GetAxis("Hand");
//Movement action //Movement action
Vector2 move = new Vector2(horizontal, vertical); movement(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);
//Actions delay //Actions delay
if(isInteracting) if(isInteracting)
@ -121,6 +112,20 @@ public class Tavernkeeper_controller : MonoBehaviour
rigidbody2d.MovePosition(position); //Movement processed by the phyisc engine for Collision, etc. 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") //Handle action with hands ("left" or "right")
void handAction(string hand) void handAction(string hand)
{ {