EnumPlayerDirection GetPlayerDirection(Vector2 PlayerMovementVector) { if (Mathf.Abs(PlayerMovementVector.y) > Mathf.Abs(PlayerMovementVector.x)) { if (PlayerMovementVector.y > 0) { PlayerDirection = EnumPlayerDirection.Up; } if (PlayerMovementVector.y < 0) { PlayerDirection = EnumPlayerDirection.Down; } } else { if (PlayerMovementVector.x > 0) { PlayerDirection = EnumPlayerDirection.Right; } if (PlayerMovementVector.x < 0) { PlayerDirection = EnumPlayerDirection.Left; } } return(PlayerDirection); }
public void Awake() { rigidbody2d = GetComponent <Rigidbody2D>(); skeletonAnimation = GetComponentInChildren <SkeletonAnimation>(); animator = GetComponentInChildren <Animator>(); LastVelocity = Vector2.zero; PlayerDirection = EnumPlayerDirection.Right; }
// Update is called once per frame void FixedUpdate() { if (!GameRule.get.IsGameActive()) { rigidbody2d.velocity = Vector3.zero; LastVelocity = Vector3.zero; return; } Vector2 PlayerInput = GetPlayerInputVector(); PlayerDirection = GetPlayerDirection(PlayerInput); rigidbody2d.velocity = Vector3.zero; rigidbody2d.velocity = PlayerInput * PlayerMovementSpeed; LastVelocity = rigidbody2d.velocity; }