예제 #1
0
    // Update is called once per frame
    void Update()
    {
        x = Input.GetAxis("Horizontal");
        z = Input.GetAxis("Vertical");

        if (Input.GetButtonDown("Jump") && isGrounded)
        {
            state      = CharacterStateEnum.JUMPING;
            velocity.y = Mathf.Sqrt(jumpHeight * -3f * gravity);

            animator.SetInteger("state", (int)state);
            print((int)state);
            return;
        }

        if (!isGrounded && velocity.y < -0.4)
        {
            state      = CharacterStateEnum.FALLING;
            velocity.y = -1f;
        }

        isGrounded = Physics.CheckSphere(flagGround.position, groundDistance, groundMask);

        movimento = transform.right * x + transform.forward * z;

        if (state == CharacterStateEnum.JUMPING)
        {
            velocity.y = Mathf.Sqrt(jumpHeight * -3f * gravity);
        }
        velocity.y += gravity * Time.deltaTime;
        ChangeStateUpdate();

        controller.Move(movimento * speed * Time.deltaTime);
        controller.Move(velocity * Time.deltaTime);
    }
 public void CheckForTranstion(CharacterStateEnum stateToCheck)
 {
     if (controller.GetState(stateToCheck).IsReadyForTransition())
     {
         controller.ChangeState(stateToCheck);
     }
 }
예제 #3
0
 /// <summary>
 /// Metodo responsavel por gerenciar a morte do personagem
 /// </summary>
 public void DoDie()
 {
     _hookWeapon.UnDoHooking();
     CharacterState = CharacterStateEnum.Dead;
     _audioSource.Stop();
     _audioSource.clip = AudioDeath;
     _audioSource.Play();
 }
예제 #4
0
 // Start is called before the first frame update
 protected void Start()
 {
     health_       = 0;
     armor_        = 0;
     damage_       = 0;
     speed_        = 0;
     rigidBidy2D_  = GetComponent <Rigidbody2D>();
     animator_     = GetComponent <Animator>();
     currentState_ = CharacterStateEnum.WALKING;
 }
예제 #5
0
    protected IEnumerator AttackCo()
    {
        animator_.SetBool("isAttacking", true);
        currentState_ = CharacterStateEnum.ATTACKING;
        yield return(null);

        animator_.SetBool("isAttacking", false);
        yield return(new WaitForSeconds(.3f));

        currentState_ = CharacterStateEnum.WALKING;
    }
예제 #6
0
    /// <summary>
    /// Metodo responsable por gerenciar o estado do personagem
    /// </summary>
    private void SetCharacterState()
    {
        if (CharacterState != CharacterStateEnum.Dead)
        {
            if (!OnFloor && StartJumping)
            {
                StartJumping   = false;
                CharacterState = CharacterStateEnum.Jumping;
                return;
            }

            // Check if the player is on a Stair
            if (OnStair && CharacterState == CharacterStateEnum.Climbing)
            {
                return;
            }
            else if (OnStair && MovingToY == 1)
            {
                CharacterState = CharacterStateEnum.Climbing;

                // Corrige a posicao do personagem em relacao a escada
                transform.position = new Vector3(StairCollider.bounds.center.x, transform.position.y, transform.position.z);
                return;
            }

            if (OnJumpinWall)
            {
                CharacterState = CharacterStateEnum.JumpingWall;
                return;
            }

            if (!OnFloor)
            {
                StartJumping   = false;
                CharacterState = CharacterStateEnum.Jumping;
                return;
            }

            if (OnFloor && _rigidBody.velocity.x != 0)
            {
                CharacterState = CharacterStateEnum.Running;
                return;
            }

            CharacterState = CharacterStateEnum.Idle;
        }
    }
예제 #7
0
    private void ChangeStateUpdate()
    {
        if (isGrounded)
        {
            if (z > 0 && x == 0)
            {
                if (Input.GetKey(KeyCode.LeftShift))
                {
                    state = CharacterStateEnum.RUNNING;
                    speed = 5f;
                }
                else
                {
                    state = CharacterStateEnum.WALKING;
                    speed = 1f;
                }
            }
            else if (x == 0 && z == 0)
            {
                state = CharacterStateEnum.IDLE;
                speed = 1f;
            }
            else if (z < 0 && x == 0)
            {
                state = CharacterStateEnum.WALKING_BACKWARDS;
                speed = 1f;
            }
            else if (z > 0 && x > 0)
            {
                state = CharacterStateEnum.DIAGONAL_WALKING_FRONT_RIGHT;
                speed = 1f;
            }
            else if (z < 0 && x > 0)
            {
                state = CharacterStateEnum.DIAGONAL_WALKING_BACK_RIGHT;
                speed = 1f;
            }
            else if (z == 0 && x > 0)
            {
                state = CharacterStateEnum.STRAFING_RIGHT;
                speed = 1f;
            }
            else if (z > 0 && x < 0)
            {
                state = CharacterStateEnum.DIAGONAL_WALKING_FRONT_LEFT;
                speed = 1f;
            }
            else if (z < 0 && x < 0)
            {
                state = CharacterStateEnum.DIAGONAL_WALKING_BACK_LEFT;
                speed = 1f;
            }
            else if (z == 0 && x < 0)
            {
                state = CharacterStateEnum.STRAFING_LEFT;
                speed = 1f;
            }
        }

        animator.SetInteger("state", (int)state);
        print((int)state);
    }
예제 #8
0
 void Start()
 {
     state = CharacterStateEnum.IDLE;
 }
예제 #9
0
 /// <summary>
 /// Metodo responsavel por gerenciar o respawn do personagem
 /// </summary>
 public void Respawn()
 {
     CharacterState     = CharacterStateEnum.Idle;
     transform.position = LastCheckPoint;
 }