Beispiel #1
0
 // Update is called once per frame
 void Update()
 {
     playerAnimations.SetFloat("HorizontalVal", movement.velocity.x);
     //Debug.Log("not moving");
     if ((Input.GetKey(KeyCode.Space) || Input.GetKeyDown(KeyCode.Space)) && skeleton.IsTouchingLayers(LayerMask.GetMask("Ground")) && (!isTochingFloatingPlatform || isTouchingMovementArea))
     {
         print("I jumped!");
         movement.AddForce(new Vector2(0, 250f));
         playerAnimations.SetFloat("HorizontalVal", movement.velocity.x);
     }
     else if ((Input.GetKey(KeyCode.D) || Input.GetKeyDown(KeyCode.D)))
     {
         if (skeleton.IsTouchingLayers(LayerMask.GetMask("Ground")) && (!isTochingFloatingPlatform || isTouchingMovementArea))
         {
             movement.AddForce(new Vector2(7.0f, 100.0f));
         }
         else
         {
             movement.AddForce(new Vector2(7.0f, 0));
         }
         playerAnimations.SetFloat("HorizontalVal", movement.velocity.x);
     }
     else if ((Input.GetKey(KeyCode.A) || Input.GetKeyDown(KeyCode.A)))
     {
         if (skeleton.IsTouchingLayers(LayerMask.GetMask("Ground")) && (!isTochingFloatingPlatform || isTouchingMovementArea))
         {
             movement.AddForce(new Vector2(-7.0f, 100.0f));
         }
         else
         {
             movement.AddForce(new Vector2(-7.0f, 0));
         }
         playerAnimations.SetFloat("HorizontalVal", movement.velocity.x);
     }
 }
Beispiel #2
0
 void Die(){
     if (bodyCollider.IsTouchingLayers(LayerMask.GetMask("Hazard"))){
         //isAlive = false;
         print("died");
         FindObjectOfType<GameSession>().ProcessPlayerDeath();
     }
 }
Beispiel #3
0
    // Update is called once per frame

    private void Update()
    {
        if (!alive)
        {
            return;
        }

        bool mask = boxcol.IsTouchingLayers(LayerMask.GetMask("Ground"));

        anim.SetBool("Land", mask);
        if (Input.GetKeyDown(KeyCode.Q) && mask && !col.IsTouchingLayers(LayerMask.GetMask("Ladder")))
        {
            dash = true;
            rolling();
        }
        if (Input.GetKeyUp(KeyCode.Q))
        {
            dash = false;
        }

        if (!dash)
        {
            jump(mask);
            Movement();
            Flip();
            climb();
        }
        die();
    }
Beispiel #4
0
    //if the players collider is touching bug, then do death
    private void Death()
    {
        // if the player has collision with the enemy layer,
        if (myBodyCollider2D.IsTouchingLayers(LayerMask.GetMask("Enemies")))
        {
            isAlive = false;
            //triggers to state of death in unity hub
            myAnimator.SetTrigger("Death");
            //gets the ridgidbody to have a velocity of deathKick, deathKick throws player up in the air
            transform.Rotate(0, 0, 90);
            GetComponent <Rigidbody2D>().velocity = deathKick;
            FindObjectOfType <GameSession>().ProcessPlayerDeath();
        }

        if (myBodyCollider2D.IsTouchingLayers(LayerMask.GetMask("Waters")))
        {
            isAlive = false;
            //triggers to state of death in unity hub
            myAnimator.SetTrigger("Death");
            //gets the ridgidbody to have a velocity of deathKick, deathKick throws player up in the air
            transform.Rotate(0, 0, 90);
            GetComponent <Rigidbody2D>().velocity = deathKick;
            FindObjectOfType <GameSession>().ProcessPlayerDeath();
        }
    }
Beispiel #5
0
 // Update is called once per frame
 void Update()
 {
     if (!Death)
     {
         Running();
         Checkfalling();
         if (boxcollider.IsTouchingLayers(ground))
         {
             Jumping();
         }
         Inair();
         Flipsprite();
     }
     else
     {
         if (!Cutscene)
         {
             if (boxcollider.IsTouchingLayers(ground))
             {
                 playercontroller.SetBool("Death ground", true);
                 StartCoroutine(Despawn());
             }
         }
     }
 }
Beispiel #6
0
 private void ClimbLadder()// TODO: Add velocity to form jumping onto ladder
 {
     if (BodyCollider.IsTouchingLayers(LayerMask.GetMask("Ladders")))
     {
         myRigidBody.gravityScale = 0;
         if (Mathf.Abs(myRigidBody.velocity.y) > 0 && BodyCollider.IsTouchingLayers(LayerMask.GetMask("Ladders")))
         {
             myAnimator.SetBool("Climbing", true);
         }
         float   controlThrow  = CrossPlatformInputManager.GetAxis("Vertical");
         Vector2 climbVelocity = new Vector2(myRigidBody.velocity.x, controlThrow * climbSpeed);
         myRigidBody.velocity = climbVelocity;
     }
     else
     {
         myRigidBody.gravityScale = 1;
     }
     if (!BodyCollider.IsTouchingLayers(LayerMask.GetMask("Ladders")))
     {
         myAnimator.SetBool("Climbing", false);
     }
     if (Mathf.Abs(myRigidBody.velocity.y) < 1 && BodyCollider.IsTouchingLayers(LayerMask.GetMask("Ladders")))
     {
         myAnimator.speed = 0;
     }
     else
     {
         myAnimator.speed = 1;
     }
 }
Beispiel #7
0
    private void ClimbLadder()
    {
        // Bool to keep track of whether we are colliding with a ladder or not
        bool isTouchingLadder = myBodyCollider.IsTouchingLayers(LayerMask.GetMask("Ladder"));

        // if we're not touching the ladder then set animation back to idle
        // and gravityScale back to what it started at
        if (!isTouchingLadder)
        {
            myAnimator.SetBool(isClimbing, false);
            myRigidbody.gravityScale = gravityScaleAtStart;
            return;
        }

        // Get rid of gravity for our player and grab our control throw in the vertical direction
        myRigidbody.gravityScale = 0f;
        float controlThrow = Input.GetAxis("Vertical"); // value is from -1 to +1

        // Set our y velocity and then set myRigidBody's velocity
        Vector2 climbVelocity = new Vector2(myRigidbody.velocity.x * horizontalLadderSpeedMultiplier, controlThrow * climbSpeed);

        myRigidbody.velocity = climbVelocity;

        // If the player has vertical speed then set its animation state to climbing
        bool playerHasVerticalSpeed = Mathf.Abs(myRigidbody.velocity.y) > Mathf.Epsilon;

        myAnimator.SetBool(isClimbing, playerHasVerticalSpeed);
    }
    private void UpdateGrounding()
    {
        //Check if character is falling using the y velocity
        if (controllerRB.velocity.y < 0.0f)
        {
            isJumping = false;
        }

        //Check for ground type or whether or not the character is on ground.
        if (controllerCollider.IsTouchingLayers(softGroundMask))
        {
            isOnGround        = true;
            currentGroundType = softGroundMask;
        }
        else if (controllerCollider.IsTouchingLayers(hardGroundMask))
        {
            isOnGround        = true;
            currentGroundType = hardGroundMask;
        }
        else
        {
            isOnGround = false;
        }

        //Check whether or not the character is in contact with a wall
        if (controllerCollider.IsTouchingLayers(wallMask))
        {
            isOnWall = true;
        }
        else
        {
            isOnWall = false;
        }
    }
Beispiel #9
0
 private void CheckGrounded()
 {
     isGrounded = myFeet.IsTouchingLayers(LayerMask.GetMask("Ground")) ||
                  myFeet.IsTouchingLayers(LayerMask.GetMask("Wall")) ||
                  myFeet.IsTouchingLayers(LayerMask.GetMask("MovingPlatform")) ||
                  myFeet.IsTouchingLayers(LayerMask.GetMask("OneWayPlatform"));
 }
Beispiel #10
0
    private void SetPlayerState()
    {
        // Jump
        if (!coll.IsTouchingLayers(ground))
        {
            if (rb.velocity.y < 0.1f)
            {
                currentState = 3;
            }
            else
            {
                currentState = 2;
            }
        }
        else if (Mathf.Abs(horizontalMove) > 0.1f)
        {
            currentState = 1;
        }
        else
        {
            currentState = 0;
        }

        anim.SetInteger("state", currentState);
    }
Beispiel #11
0
 private void OnCollisionEnter2D(Collision2D collision)
 {
     if (inTheAir && !myCapsuleCollider2D.IsTouchingLayers(LayerMask.GetMask("Ground")))
     {
         timer = timer1 - timer2;
         if (timer > 1.1f)
         {
             timer = 5f;
         }
         else if (timer > 0.8f)
         {
             timer = 1f;
         }
         else if (timer > 0.5f)
         {
             timer = 0.5f;
         }
         else
         {
             timer = 0.2f;
         }
         dustAnimator.SetTrigger("Landing");
         AudioSource.PlayClipAtPoint(landingSFX, Camera.main.transform.position);
         TriggerLandingCameraShake();
     }
     if (!myCapsuleCollider2D.IsTouchingLayers(LayerMask.GetMask("Ground")) && isOnALadder)
     {
         timer = .4f;
         dustAnimator.SetTrigger("Landing");
         AudioSource.PlayClipAtPoint(landingSFX, Camera.main.transform.position);
         TriggerLandingCameraShake();
     }
 }
Beispiel #12
0
    private void InputManager()
    {
        //Move Left
        if (Input.GetAxis("Horizontal") < 0)
        {
            _Rigidbody2D.velocity = new Vector2(-_Speed, _Rigidbody2D.velocity.y);
            transform.localScale  = new Vector2(-1, 1);
        }

        //Move Right
        if (Input.GetAxis("Horizontal") > 0)
        {
            _Rigidbody2D.velocity = new Vector2(_Speed, _Rigidbody2D.velocity.y);
            transform.localScale  = new Vector2(1, 1);
        }

        //Jump
        if ((Input.GetAxis("Jump") > 0) && _CapsuleCollider2D.IsTouchingLayers())
        {
            _Rigidbody2D.velocity = new Vector2(_Rigidbody2D.velocity.x, _JumpForce);
            playerstate           = PlayerState.Jump;
        }

        //Crouch
        if (Input.GetAxis("Vertical") < 0)
        {
            playerstate = PlayerState.Crouch;
        }
    }
Beispiel #13
0
    private void Climbing()
    {
        if (!myCollider.IsTouchingLayers(LayerMask.GetMask("Climable"))) {
            isClimbing = false;
            anim.SetBool("climbing", isClimbing);
            rb.gravityScale = initialGravity;
            return;
        }

        float controlThrowVertical = CrossPlatformInputManager.GetAxisRaw("Vertical");
        if (controlThrowVertical > 0 && !isClimbing)
        {
            isClimbing = true;
            rb.velocity = new Vector2(0, 0);
            midAirJumps = 0;
            currentDashes = 0;
            // sets velocity to 0
            rb.gravityScale = 0;
        }

        if (controlThrowVertical > 0.2f) controlThrowVertical = 1;
        else if (controlThrowVertical < -0.2f) controlThrowVertical = -1;
        else controlThrowVertical = 0;

        if (isClimbing)
        {
            rb.velocity = new Vector2(0, controlThrowVertical * climbSpeed * Time.fixedDeltaTime);
            currentDashes = 0;
            anim.SetBool("climbing", isClimbing);
            anim.SetFloat("velocityY", Mathf.Abs(controlThrowVertical));
        }
    }
Beispiel #14
0
    void Climbing()
    {
        if (!myBodyCollider.IsTouchingLayers(LayerMask.GetMask("Climbing")))
        {
            myAnimator.SetBool("isOnLadder", false);
            myAnimator.SetBool("isClimbing", false);
            myRigidBody.gravityScale = initialGravityScale;
            return;
        }
        else if (myBodyCollider.IsTouchingLayers(LayerMask.GetMask("Climbing")))
        {
            myAnimator.SetBool("isOnLadder", true);
            myRigidBody.gravityScale = 0f;
        }

        GettingPlayerVerticalMovement();

        Vector2 playerMove = new Vector2(myRigidBody.velocity.x, verticalMove * walkSpeed);

        myRigidBody.velocity = playerMove;

        if (Mathf.Abs(verticalMove) > Mathf.Epsilon)
        {
            myAnimator.SetBool("isClimbing", true);
        }
    }
Beispiel #15
0
 private void NextLevelCollisionCheck()
 {
     if (myBodyCollider2d.IsTouchingLayers(LayerMask.GetMask("LevelTransition")))
     {
         levelLoader.LoadNextLevel();
     }
 }
Beispiel #16
0
 private void HitWall()
 {
     if (myBodyCollider.IsTouchingLayers(LayerMask.GetMask("Wall")))
     {
         Debug.Log("Hit wall.");
         return;
     }
 }
Beispiel #17
0
 // Checks if either of the player's colliders are touching a hazard, and kills the player if so
 private void HazardsCheck()
 {
     if ((myBodyCollider2D.IsTouchingLayers(LayerMask.GetMask(HAZARDS_LAYER))) ||
         (myFeetCollider2D.IsTouchingLayers(LayerMask.GetMask(HAZARDS_LAYER))))
     {
         Die();
     }
 }
Beispiel #18
0
 private void GatherGems()
 {
     if (myfeetcollider.IsTouchingLayers(LayerMask.GetMask("Crystal")) ||
         mybodycollider.IsTouchingLayers(LayerMask.GetMask("Crystal")))
     {
         Debug.Log("Touched gem");
     }
 }
Beispiel #19
0
 private void TakeTrapDamage()
 {
     if (myBodyCollider.IsTouchingLayers(LayerMask.GetMask("Traps")))
     {
         Debug.Log("OH YOU ARE TAKING DAMAGE!!");
         // call takePlayerHealth here pass in int as the damage
     }
 }
Beispiel #20
0
 private void Health()
 {
     if (myBodyCollider.IsTouchingLayers(LayerMask.GetMask("Enemy")) && !invuln)
     {
         hp--;
         invuln = true;
         Debug.Log(hp);
     }
 }
Beispiel #21
0
 void OnTriggerExit2D(Collider2D other)
 {
     // si un enemigo golpea el headcollider no hacer flip
     if (myHeadCollider2D.IsTouchingLayers(LayerMask.GetMask("Player")))
     {
         return;
     }
     // Si llegaste al final del camino, hacer flip al sprite
     transform.localScale = new Vector2(-Mathf.Sign(myRigidbody2D.velocity.x), 1f);
 }
Beispiel #22
0
 void OnCollisionEnter2D(Collision2D other)
 {
     if (_bodyCollider.IsTouchingLayers(_enemyMask))
     {
         Damage(enemyDamage);
     }
     else if (_bodyCollider.IsTouchingLayers(_hazardsMask))
     {
         Damage(hazardsDamage);
     }
 }
Beispiel #23
0
 private void HandleHit()
 {
     if (_collider.IsTouchingLayers(LayerMask.GetMask("Enemy")))
     {
         StartCoroutine(BlinkPlayer());
         _healthSystem.DecreaseHealth();
         // Dá um tempo pro jogador fugir dos inimigos antes de levar um hit novamente.
         DisableCollider();
         Invoke(nameof(EnableCollider), 2f);
     }
 }
Beispiel #24
0
    // Swim ======================================

    private void Swim()
    {
        if (!myBodyCollider.IsTouchingLayers(LayerMask.GetMask("Water")))
        {
            //Debug.Log("Not in wota");
            //SetGravityScale(gravityScale);
            return;
        }
        Debug.Log("In WOTA");
        SetGravityScale(0.5f);
    }
Beispiel #25
0
 private void OnTriggerEnter2D(Collider2D collision)
 {
     if (myCapsuleCollider.IsTouchingLayers(LayerMask.GetMask("Player")) && enemy.playerHitMe == false)
     {
         transform.localScale = new Vector2(-(Mathf.Sign(myRigidBody.velocity.x)), 1f);
     }
     if (myCapsuleCollider.IsTouchingLayers(LayerMask.GetMask("Player")) && enemy.playerHitMe == true)
     {
         enemy.playerHitMe = false;
     }
 }
 //GroundCheck
 //If the capsul collider is colliding with ground then isGrounded becomes true.
 private void UpdateGroundCheck()
 {
     if ((capsule.IsTouchingLayers(LayerMask.GetMask("Ground"))) || (capsule.IsTouchingLayers(LayerMask.GetMask("Mob"))) || capsule.IsTouchingLayers(LayerMask.GetMask("Ghost")))
     {
         onGround = true;
     }
     else
     {
         onGround = false;
     }
 }
    private void die() //player death
    {
        //if player collider touches anything from enemy class
        if (playerBodyCollider.IsTouchingLayers(LayerMask.GetMask("Enemy")))
        {
            playerAlive = false; //stop player movement controls on death
            //issues with line above: Need to add other controls (shooting for ex) + when moving on death, player continues to move

            playerCharacterAnimator.SetTrigger("Dying");           //trigger death anim
            GetComponent <Rigidbody2D>().velocity = deathPushBack; //testing visually that player died
        }
    }
Beispiel #28
0
    private void Climb()
    {
        if (!bodyCollider.IsTouchingLayers(LayerMask.GetMask("Climbing")))   //if player isn't touching ladder return
        {
            return;
        }

        float   controlClimb  = CrossPlatformInputManager.GetAxis("Vertical");
        Vector2 climbVelocity = new Vector2(playerRigidBody.velocity.x, controlClimb * climbSpeed);

        playerRigidBody.velocity = climbVelocity;
    }
Beispiel #29
0
    //this puts us back into IDLE when standing under/near ladders and megaman is not moving horizontally
    private void TestGroundAndClimbCollision()
    {
        bool playerHasHorizontalSpeed = Mathf.Abs(myRigidBody.velocity.x) > Mathf.Epsilon;

        if (myFeetCollider.IsTouchingLayers(LayerMask.GetMask("Ground")) == true && myBodyCollider.IsTouchingLayers(LayerMask.GetMask("Climbing")) == true && playerHasHorizontalSpeed == false)
        {
            myAnimator.enabled = true;
            myAnimator.SetBool("Jumping", false);
            myAnimator.SetBool("Climbing", false);
            myAnimator.SetBool("Running", false);
        }
    }
Beispiel #30
0
 private void Jump()
 {
     if (!myBodyCollider.IsTouchingLayers(LayerMask.GetMask("Ground")))
     {
         return;
     }
     if (Input.GetButtonDown("Vertical_Player2"))
     {
         Vector2 jumpVelocityToAdd = new Vector2(0f, jumpSpeed);
         myRigidBody2.velocity += jumpVelocityToAdd;
     }
 }