Example #1
0
            private void HandleComputeMoveDirection()
            {
                if (Controller.InputingMovement == false)
                {
                    _movementDirection = TMovementDirection.None;
                }
                else
                {
                    //Get the angle
                    Vector2 moveDir   = Controller.MoveInput.normalized;
                    float   moveAngle = (moveDir.y < 0 ? -Mathf.Acos(moveDir.x) : Mathf.Acos(moveDir.x));

                    //To prevent negative angle
                    if (moveAngle <= 0f)
                    {
                        moveAngle += Mathf.PI * 2f;
                    }
                    //To prevent above 2PI angle
                    moveAngle %= Mathf.PI * 2f;

                    //So we have angleStep = 1 / 8 of 2PI, and we have 8 possible directions
                    float angleStep = Mathf.PI / 4f;

                    //Now moveAngle will have 0 if we are going right, 1 if upright, 2 if up, etc.
                    moveAngle /= angleStep;

                    //We add +1 because of TMovementDirection.None taking the ID 0
                    int movementDirectionIndex = Mathf.FloorToInt(moveAngle) + 1;

                    //Finally, assign the movement direction
                    _movementDirection = (TMovementDirection)movementDirectionIndex;
                }
            }
Example #2
0
 private void OnStartInteract(TEntity master, ITInteractable interactable)
 {
     References.Rigidbody.velocity = Vector2.zero;
     _movementDirection            = TMovementDirection.None;
 }