Ejemplo n.º 1
0
    private bool IsGrounded(Rigidbody2D MyRigidbody)
    {
        if (MyRigidbody.velocity.y <= 0.2)
        {
            //MyRigidbody.velocity += Vector2.up * Physics2D.gravity.y * (fallMultiplier - 1) * Time.deltaTime;
            foreach (Transform point in groundPoints)
            {
                //Gets the colliders on the player's feet
                Collider2D[] colliders = Physics2D.OverlapCircleAll(point.position, groundRadius, groundMask);

                for (int i = 0; i < colliders.Length; i++)
                {
                    if (colliders[i].gameObject != gameObject && (colliders[i].gameObject.CompareTag("Floor") || ((this.gameObject.layer == 9 && colliders[i].gameObject.layer == 8) || (this.gameObject.layer == 8 && colliders[i].gameObject.layer == 9))))
                    {
                        //If the colliders collide with something else than the player, then the players is grounded
                        canJump   = true;
                        isJumping = false;
                        MyAnimator.ResetTrigger("Jump");
                        if (MyAnimator.GetBool("Land"))
                        {
                            MyAnimator.SetBool("Land", false);
                            AudioManager.instance.Play(gameObject.name + "Land");
                            StartCoroutine("LandEffect");
                        }
                        return(true);
                    }
                }
            }
        }
        return(false);
    }
Ejemplo n.º 2
0
    private void HandleMovement(float horizontal)
    {
        if (myRigidbody.velocity.y < 0)
        {
            MyAnimator.SetBool("land", true);
        }

        if (!MyAnimator.GetBool("slide") && (isGrounded || airControl))
        {
            myRigidbody.velocity = new Vector2(horizontal * movementSpeed, myRigidbody.velocity.y);
        }

        if (isGrounded && jump)
        {
            isGrounded = false;
            myRigidbody.AddForce(new Vector2(0, jumpForce));
            MyAnimator.SetTrigger("jump");
        }

        MyAnimator.SetFloat("speed", Mathf.Abs(horizontal));

        if (slide && !this.MyAnimator.GetCurrentAnimatorStateInfo(0).IsName("Slide"))
        {
            MyAnimator.SetBool("slide", true);
        }
        else if (!this.MyAnimator.GetCurrentAnimatorStateInfo(0).IsName("Slide"))
        {
            MyAnimator.SetBool("slide", false);
        }
    }
Ejemplo n.º 3
0
    private void handleMovement(float horizontal)
    {
        if (rb2d.velocity.y < 0)
        {
            MyAnimator.SetBool("Land", true);
        }

        if (!MyAnimator.GetBool("slide") && !this.MyAnimator.GetCurrentAnimatorStateInfo(0).IsTag("Attack") && (isGrounded || airControl))
        {
            rb2d.velocity = new Vector2(horizontal * speed, rb2d.velocity.y);
        }

        if (isGrounded && jump)
        {
            isGrounded = false;
            rb2d.AddForce(new Vector2(0, jumpForce));
            MyAnimator.SetTrigger("Jump");
        }

        if (slide && !this.MyAnimator.GetCurrentAnimatorStateInfo(0).IsName("Slide2"))
        {
            MyAnimator.SetBool("slide", true);
        }
        else if (!this.MyAnimator.GetCurrentAnimatorStateInfo(0).IsName("Slide2"))
        {
            MyAnimator.SetBool("slide", false);
        }

        MyAnimator.SetFloat("speed", Mathf.Abs(horizontal));
    }
Ejemplo n.º 4
0
 public override void MakeAction()
 {
     if (!MyAnimator.GetBool("isWalking"))
     {
         MyAnimator.SetBool("isWalking", true);
     }
 }
    public override IEnumerator TakeDamage()
    {
        if (!MyAnimator.GetBool("slide"))
        {
            if (canDamage)
            {
                healthStat.CurrentVal -= 10;

                canDamage = false;

                if (!IsDead)
                {
                    MyAnimator.SetBool("damage", true);

                    StartCoroutine(IndicateImmortal());

                    StartCoroutine(AnimatorTransitionTimer(0.14f));

                    StartCoroutine(TransitionAfterDelay(1.2f));
                }
                else
                {
                    MyAnimator.SetBool("die", true);

                    Death();

                    //MyRigidbody.velocity.x = Vector2.zero;

                    yield return(null);
                }
            }
        }
    }
    private void HandleMovement(float horizontal)
    {
        if (MyRigidbody.velocity.y < 0 && !OnGround)
        {
            MyAnimator.SetBool("falling", true);

            MyAnimator.SetBool("jump bool", false);
        }

        if (MyRigidbody.velocity.y == 0 && Time.time - jumpTime > 0.10)
        {
            MyAnimator.SetBool("jump bool", false);
        }

        if (!MyAnimator.GetBool("slide") && (OnGround || airControl))
        {
            MyRigidbody.velocity = new Vector2(horizontal * movementSpeed, MyRigidbody.velocity.y);
        }

        if (OnGround && Jump)
        {
            OnGround = false;

            MyRigidbody.AddForce(new Vector2(0, jumpForce));
        }

        MyAnimator.SetFloat("speed", Mathf.Abs(horizontal));
    }
Ejemplo n.º 7
0
    public void SetJumpingFallingAnim(float yVelocity)
    {
        bool falling = yVelocity < 0 && Controller.collisionInfo.below == false /*&& MyAnimator.GetBool(arialHash) == false*/;
        bool jumping = yVelocity > 0 && Controller.collisionInfo.below == false /*&& MyAnimator.GetBool(arialHash) == false*/;


        if (MyAnimator.GetBool(fallHash) != falling)
        {
            MyAnimator.SetBool(fallHash, falling);
        }

        if (MyAnimator.GetBool(jumpHash) != jumping)
        {
            MyAnimator.SetBool(jumpHash, jumping);
        }
    }
Ejemplo n.º 8
0
    private void HandleInput()
    {
        // Player presses the attack button
        if (Input.GetKeyDown(KeyCode.Space))
        {
            Instance.healthStat.CurrentHp -= 1f;
            // if the player has claws do the claws animation
            if (Instance.HasClaws == true)
            {
                if (isClawing == false)
                {
                    if (MyAnimator.GetBool("FacingNorth") == true)
                    {
                        isClawing         = true;
                        currentChargeTime = initialChargeTime;
                        Instance.VFXClaw.transform.localPosition = new Vector3(0, -3f, 0);
                        Instance.VFXClaw.transform.localRotation = Quaternion.Euler(0, 0, 90);
                        Instance.VFXClaw.transform.localScale    = new Vector3(0.5f, 0.5f, 2);
                        VFXClaw.SetActive(true);
                        PlayerController.Instance.VFXClaw.GetComponent <ParticleSystem>().Play();
                        VFXClaw.GetComponent <Animator>().SetTrigger("ClawAttack");
                        Debug.Log("Striked with claws!");
                    }
                    if (MyAnimator.GetBool("FacingSouth") == true)
                    {
                        isClawing         = true;
                        currentChargeTime = initialChargeTime;
                        Instance.VFXClaw.transform.localPosition = new Vector3(0, 3f, 0);
                        Instance.VFXClaw.transform.localRotation = Quaternion.Euler(0, 0, 90);
                        Instance.VFXClaw.transform.localScale    = new Vector3(-0.5f, -0.5f, 2);
                        VFXClaw.SetActive(true);
                        PlayerController.Instance.VFXClaw.GetComponent <ParticleSystem>().Play();
                        VFXClaw.GetComponent <Animator>().SetTrigger("ClawAttack");
                        Debug.Log("Striked with claws!");
                    }
                    if (MyAnimator.GetBool("FacingWest") == true)
                    {
                        isClawing         = true;
                        currentChargeTime = initialChargeTime;
                        Instance.VFXClaw.transform.localPosition = new Vector3(3f, 0, 0);
                        Instance.VFXClaw.transform.localRotation = Quaternion.Euler(0, 0, 0);
                        Instance.VFXClaw.transform.localScale    = new Vector3(-0.5f, -0.5f, 2);
                        VFXClaw.SetActive(true);
                        PlayerController.Instance.VFXClaw.GetComponent <ParticleSystem>().Play();
                        VFXClaw.GetComponent <Animator>().SetTrigger("ClawAttack");
                        Debug.Log("Striked with claws!");
                    }
                    if (MyAnimator.GetBool("FacingEast") == true)
                    {
                        isClawing         = true;
                        currentChargeTime = initialChargeTime;
                        Instance.VFXClaw.transform.localPosition = new Vector3(-3f, 0, 0);
                        Instance.VFXClaw.transform.localRotation = Quaternion.Euler(0, 0, 0);
                        Instance.VFXClaw.transform.localScale    = new Vector3(0.5f, 0.5f, 2);
                        VFXClaw.SetActive(true);
                        PlayerController.Instance.VFXClaw.GetComponent <ParticleSystem>().Play();
                        VFXClaw.GetComponent <Animator>().SetTrigger("ClawAttack");
                        Debug.Log("Striked with claws!");
                    }
                }
            }
            // if player has horns do the horns animation
            if (Instance.HasHorns == true)
            {
                if (isCharging == false && FreezeControls == false)
                {
                    if (MyAnimator.GetBool("FacingNorth") == true)
                    {
                        isCharging        = true;
                        currentChargeTime = initialChargeTime;
                        Instance.VFXCharge.transform.localPosition = new Vector3(0.2f, -2f, 0);
                        Instance.VFXCharge.transform.localRotation = Quaternion.Euler(0, 0, 90);
                        Instance.VFXCharge.transform.localScale    = new Vector3(-2, 3, 2);
                        // Changes distance he moves to (the position.y + xx)
                        chargeDestination = new Vector3(MyTransform.position.x, MyTransform.position.y + chargeSpeed, MyTransform.position.z);
                        VFXCharge.SetActive(true);
                        VFXCharge.GetComponent <Animator>().SetTrigger("HornsAttack");
                        Debug.Log("Striked with horns!");
                    }
                    if (MyAnimator.GetBool("FacingSouth") == true)
                    {
                        isCharging        = true;
                        currentChargeTime = initialChargeTime;
                        Instance.VFXCharge.transform.localPosition = new Vector3(0.2f, 2, 0);
                        Instance.VFXCharge.transform.localRotation = Quaternion.Euler(0, 0, 90);
                        Instance.VFXCharge.transform.localScale    = new Vector3(2, 3, 2);
                        // Changes distance he moves to (the position.y - xx)
                        chargeDestination = new Vector3(MyTransform.position.x, MyTransform.position.y - chargeSpeed, MyTransform.position.z);
                        VFXCharge.SetActive(true);
                        VFXCharge.GetComponent <Animator>().SetTrigger("HornsAttack");
                        Debug.Log("Striked with horns!");
                    }
                    if (MyAnimator.GetBool("FacingWest") == true)
                    {
                        isCharging        = true;
                        currentChargeTime = initialChargeTime;
                        Instance.VFXCharge.transform.localPosition = new Vector3(2f, 0, 0);
                        Instance.VFXCharge.transform.localRotation = Quaternion.Euler(0, 0, 0);
                        Instance.VFXCharge.transform.localScale    = new Vector3(2, 3, 2);
                        // Changes distance he moves to (the position.x - xx)
                        chargeDestination = new Vector3(MyTransform.position.x - chargeSpeed, MyTransform.position.y, MyTransform.position.z);
                        VFXCharge.SetActive(true);
                        VFXCharge.GetComponent <Animator>().SetTrigger("HornsAttack");
                        Debug.Log("Striked with horns!");
                    }
                    if (MyAnimator.GetBool("FacingEast") == true)
                    {
                        isCharging        = true;
                        currentChargeTime = initialChargeTime;
                        Instance.VFXCharge.transform.localPosition = new Vector3(-2f, 0, 0);
                        Instance.VFXCharge.transform.localRotation = Quaternion.Euler(0, 0, 0);
                        Instance.VFXCharge.transform.localScale    = new Vector3(-2, 3, 2);
                        // Changes distance he moves to (the position.x + xx)
                        chargeDestination = new Vector3(MyTransform.position.x + chargeSpeed, MyTransform.position.y, MyTransform.position.z);
                        VFXCharge.SetActive(true);
                        VFXCharge.GetComponent <Animator>().SetTrigger("HornsAttack");
                        Debug.Log("Striked with horns!");
                    }
                }
            }
            // if player has spikes do the spikes animation
            if (Instance.HasSpikes == true)
            {
                if (isImpaling == false)
                {
                    isImpaling          = true;
                    currentImpalingTime = initialImpalingTime;
                    foreach (GameObject spikeSpawnLoc in SpikeSpawnLocs)
                    {
                        Instantiate(SpikeProjectile, spikeSpawnLoc.transform);
                    }
                    Debug.Log("Striked with spikes!");
                }
            }
        }
        if (Instance.FreezeControls == false)
        {
            if (Input.GetKey(KeyCode.W))
            {
                MyAnimator.SetBool("FacingNorth", true);
                MyAnimator.SetBool("FacingSouth", false);
                MyAnimator.SetBool("FacingWest", false);
                MyAnimator.SetBool("FacingEast", false);
                MyAnimator.SetBool("IsIdle", false);
                //Instance.healthStat.CurrentHp -= .01f;
                Instance.Health -= .01f;
                Instance.healthStat.CurrentHp = Instance.Health;
                Death();
            }
            if (Input.GetKey(KeyCode.A))
            {
                MyAnimator.SetBool("FacingNorth", false);
                MyAnimator.SetBool("FacingSouth", false);
                MyAnimator.SetBool("FacingWest", true);
                MyAnimator.SetBool("FacingEast", false);
                MyAnimator.SetBool("IsIdle", false);
                Instance.Health -= .01f;
                Instance.healthStat.CurrentHp = Instance.Health;
                Death();
            }

            if (Input.GetKey(KeyCode.S))
            {
                MyAnimator.SetBool("FacingNorth", false);
                MyAnimator.SetBool("FacingSouth", true);
                MyAnimator.SetBool("FacingWest", false);
                MyAnimator.SetBool("FacingEast", false);
                MyAnimator.SetBool("IsIdle", false);
                Instance.Health -= .01f;
                Instance.healthStat.CurrentHp = Instance.Health;
                Death();
            }
            if (Input.GetKey(KeyCode.D))
            {
                MyAnimator.SetBool("FacingNorth", false);
                MyAnimator.SetBool("FacingSouth", false);
                MyAnimator.SetBool("FacingWest", false);
                MyAnimator.SetBool("FacingEast", true);
                MyAnimator.SetBool("IsIdle", false);
                Instance.Health -= .01f;
                Instance.healthStat.CurrentHp = Instance.Health;
                Death();
            }
        }
        if (Input.GetKey(KeyCode.Q))
        {
            RandomCharacterTraitSelection();
        }
    }
Ejemplo n.º 9
0
    public void OnInjury(Vector3 normal, bool isKnockBack)
    {
        if (!isKnockBack)
        {
            if (normal != Vector3.zero)
            {
                normal = new Vector3(normal.x, 0, normal.z);
                float bodyAngle = Vector3.Angle(transform.right, normal * -1);

                if (bodyAngle <= 90)
                {
                    this.MyAnimator.SetInteger("HitType", 0);
                }
                else
                {
                    this.MyAnimator.SetInteger("HitType", 1);
                }
            }


            this.MyAnimator.SetTrigger("Hit");

            if (MyAnimator.GetBool("IsAiming"))
            {
                MyAimIK.solver.IKPositionWeight = 0;
                MyAimIK.solver.SmoothEnable(1);
            }


            MyHeadIK.Weight = 0;
            MyHeadIK.SmoothEnable(1);
        }
        else
        {
            //if normal is in front of character then knock back, other knock forward

            normal = new Vector3(normal.x, 0, normal.z);
            float bodyAngle = Vector3.Angle(transform.forward, normal * -1);

            Vector3 lookDir = normal;


            if (bodyAngle <= 90)
            {
                lookDir = normal * -1;
                MyAI.BlackBoard.AnimationAction     = AnimationActions.KnockBack;
                MyAI.BlackBoard.ActionMovementDest  = transform.position + normal.normalized * 1;                //transform.position - transform.forward * 1;
                MyAI.BlackBoard.ActionMovementSpeed = 1.5f;
            }
            else
            {
                MyAI.BlackBoard.AnimationAction     = AnimationActions.KnockForward;
                MyAI.BlackBoard.ActionMovementDest  = transform.position + normal.normalized * 1.2f;                //transform.position + transform.forward * 1.5f;
                MyAI.BlackBoard.ActionMovementSpeed = 2f;
            }

            lookDir            = new Vector3(lookDir.x, 0, lookDir.z);
            transform.rotation = Quaternion.LookRotation(lookDir);

            SendCommand(CharacterCommands.PlayAnimationAction);
        }



        _twitchTimer = 0.5f;
        ActionState  = HumanActionStates.Twitch;
    }