Esempio n. 1
0
    private void HandleMovement(float horizontal)
    {
        if (MyRigidBody.velocity.y < 0)
        {
            MyAnimator.SetBool("land", true);
        }
        if (!Attack && !Slide && !Dash && (OnGround || airControl) && !knockbackFlag && !playerDeath)// means you can't move during the !EVENT
        {
            MyRigidBody.velocity = new Vector2(horizontal * movementSpeed, MyRigidBody.velocity.y);
        }

        if (Land && Attack)                                                                   //if we are in the process of landing
        {
            MyRigidBody.AddForce(new Vector2(-1 * MyRigidBody.velocity.x * landingSpeed, 0)); //add a small force in the opposite direction that the player is moving
            if ((MyRigidBody.velocity.x == 0))                                                //or our player has stopped moving

            {
                Land = false; //consider the landing to be complete
            }
        }

        if (Jump && MyRigidBody.velocity.y == 0 && !Dash)
        {
            MyRigidBody.AddForce(new Vector2(0, jumpForce));//causes you to jump 0=x axis, jumpFroce=yaxis
        }

        MyAnimator.SetFloat("speed", Mathf.Abs(horizontal));
    }
Esempio n. 2
0
 private void TurnPlayer()
 {
     MyDirection = (MyTarget.transform.position - transform.position).normalized;
     MyAnimator.SetFloat("x", Mathf.RoundToInt(MyDirection.x));
     MyAnimator.SetFloat("y", Mathf.RoundToInt(MyDirection.y));
     MyDirection = Vector2.zero;
 }
Esempio n. 3
0
    public void HandleLayers()
    {
        if (IsAlive)
        {
            // Check if we are moving or standing still

            if (IsMoving)
            {
                // Activate Walk Layer
                ActivateLayer("WalkLayer");

                MyAnimator.SetFloat("x", Direction.x);
                MyAnimator.SetFloat("y", Direction.y);
            }
            else if (IsAttacking)
            {
                ActivateLayer("AttackLayer");
            }
            else
            {
                // Activate Idle Layer
                ActivateLayer("IdleLayer");
            }
        }
        else
        {
            ActivateLayer("DeathLayer");
        }
    }
Esempio n. 4
0
    public void Move()
    {
        if (!Attack)
        {
            if ((GetDirection().x > 0 && transform.position.x < rightEdge.position.x) || (GetDirection().x < 0 && transform.position.x > leftEdge.position.x))
            {
                MyAnimator.SetFloat("speed", 1);

                if (GetDirection().x > 0)
                {
                    transform.Translate(GetDirection() * (movementSpeed * Time.deltaTime));
                }
                else if (GetDirection().x < 0)
                {
                    transform.Translate(GetDirection() * (-movementSpeed * Time.deltaTime));
                }
            }
            else if (currentState is PatrolState)
            {
                ChangeDirection();
            }
            else if (currentState is RangedState)
            {
                Target = null;
                ChangeState(new IdleState());
            }
        }
    }
Esempio n. 5
0
 private void Wander()
 {
     if (wanderTimerState == 0)
     {
         wanderTimer += 0.1f * Time.deltaTime * wanderTimerSpeed;
         if (wanderTimer >= wanderTimerMax)
         {
             wanderTimer = 0;
             if (isMoving)
             {
                 int movDir = Random.Range(0, 8);
                 RandomizeAIDirection(movDir);
             }
             else if (isIdle)
             {
                 randomDirection.x = 0;
                 randomDirection.y = 0;
             }
         }
         // Movement
         float velocityX = randomDirection.x * Time.smoothDeltaTime * movementSpeed;
         float velocityY = randomDirection.y * Time.smoothDeltaTime * movementSpeed;
         //Debug.Log("VelocityX is " + velocityX);
         //Debug.Log("VelocityY is " + velocityY);
         if (MyAnimator != null)
         {
             MyAnimator.SetFloat("SpeedX", velocityX);
             MyAnimator.SetFloat("SpeedY", velocityY);
         }
         MyRigidbody2D.AddForceAtPosition(new Vector3(velocityX, velocityY, 0) * movementSpeed, transform.position);
     }
 }
Esempio n. 6
0
 public virtual void HandleLayers()
 {
     if (IsAlive)
     {
         //provjerava krecemo li se
         if (IsMoving)
         {
             //salje u walk
             ActivateLayer("WalkLayer");
             MyAnimator.SetFloat("MovingX", Direction.x);
             MyAnimator.SetFloat("MovingY", Direction.y);
         }
         else if (IsAttacking)
         {
             //salje u attack
             ActivateLayer("AttackLayer");
         }
         else
         {
             //vraca u idle
             ActivateLayer("IdleLayer");
         }
     }
     else
     {
         ActivateLayer("DeathLayer");
     }
 }
Esempio n. 7
0
    // Will handle movement of the player
    private void HandleMovement()
    {
        float horizontal = Input.GetAxis("Horizontal");
        float vertical   = Input.GetAxis("Vertical");

        var     worldPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
        Vector3 relativePoint = transform.InverseTransformPoint(worldPosition);

        MyAnimator.SetFloat("SpeedX", relativePoint.x);
        MyAnimator.SetFloat("SpeedY", relativePoint.y);

        inputMovement = new Vector2(horizontal, vertical);
        // Moves the player based on input * consistent time frame * speed withini the world space
        transform.Translate(inputMovement * Time.deltaTime * movementSpeed, Space.World);


        if (horizontal != 0 || vertical != 0)
        {
            MyAnimator.SetBool("walking", true);
        }
        else
        {
            MyAnimator.SetBool("walking", false);
        }
    }
Esempio n. 8
0
    private void HandleMovement(float inputX)
    {
        if (MyRigidbody.velocity.y < -0.01f)
        {
            MyAnimator.SetBool("land", true);
        }
        if (actState.Equals(ActState.StandBy) && (OnGround || airControl))
        {
            MyRigidbody.velocity = new Vector2(inputX * (base.stat.Spd.CurrentVal + runSpd), MyRigidbody.velocity.y);
        }
        if (Jump && Mathf.Abs(MyRigidbody.velocity.y) < 0.01f)
        {
            MyRigidbody.AddForce(new Vector2(0, jumpForce));
        }
        if (Input.GetKey(KeyCode.LeftShift))
        {
            runSpd = 2;
        }
        else
        {
            runSpd = 0;
        }

        MyAnimator.SetFloat("speed", Mathf.Abs(inputX));
    }
    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));
    }
Esempio n. 10
0
    /// <summary>
    /// Regarde en direction de la cible
    /// </summary>
    private void LookAtTarget()
    {
        // si j'ai une cible
        if (MyTarget != null)
        {
            // Direction de la cible
            Vector2 directionToTarget = (MyTarget.transform.position - transform.position).normalized;

            // Ma direction
            Vector2 myDirection = new Vector2(MyAnimator.GetFloat("x"), MyAnimator.GetFloat("y"));

            // Angle de vision de la cible
            float angleToTarget = Vector2.Angle(myDirection, directionToTarget);

            if (angleToTarget > fieldOfView / 2)
            {
                // Ajuste la direction
                MyAnimator.SetFloat("x", directionToTarget.x);
                MyAnimator.SetFloat("y", directionToTarget.y);

                // Actualise la direction
                updateDirection = true;
            }
        }
    }
Esempio n. 11
0
 //new HandleMovement
 private void HandleMovement(float horizontal)
 {
     if (MyRigidbody.velocity.y < 0)
     {
         MyAnimator.SetBool("land", true);
     }
     // causes unable to jump when tapping fast //if (Jump && OnGround && (MyRigidbody.velocity.y == 0)) // || MyRigidbody.velocity.y > -8.8
     //if (Jump && GroundCheck() && btnJumping == true) // || MyRigidbody.velocity.y > -8.8
     //{
     //    MyRigidbody.velocity = Vector2.up * jumpVelocity;
     //    //source.PlayOneShot(jumpSound, 0.13F);
     //}
     if (!Attack && !Slide && (GroundCheck() || airControl)) // add one for aircontrool and in air and slow it down
     {
         MyRigidbody.velocity = new Vector2(horizontal * movementSpeed, MyRigidbody.velocity.y);
     }
     if (Attack && !Slide && (GroundCheck() || airControl))
     {
         MyRigidbody.velocity = new Vector2(horizontal * movementSpeed / 1.8f, MyRigidbody.velocity.y);
     }
     //if (Jump && GroundCheck() && (MyRigidbody.velocity.y < 0)) // || MyRigidbody.velocity.y > -8.8
     //{
     //    Debug.Log("tried to jump but velocity Y is < 0 = " + MyRigidbody.velocity.y);
     //}
     MyAnimator.SetFloat("speed", Mathf.Abs(horizontal));
 }
Esempio n. 12
0
 public virtual void HandleLayers()
 {
     if (IsAlive)
     {
         //if player is moving = do the animation
         if (IsMoving)
         {
             ActivateLayer("Walk Layer"); //layer weight use to show specific layers the higher the weight
             MyAnimator.SetFloat("x", Direction.x);
             MyAnimator.SetFloat("y", Direction.y);
         }
         else if (IsAttacking)
         {
             ActivateLayer("Attack Layer");
         }
         //else if not moving = set layer weight of layer 1 to 0 (to show idle)
         else
         {
             ActivateLayer("Idle Layer"); //layer weight use to show specific layers the higher the weight
         }
     }
     else
     {
         ActivateLayer("Death Layer"); //actiavte layer if not alive
     }
 }
Esempio n. 13
0
    public void Move()
    {
        if (facingRight)
        {
            transform.Translate(Vector2.right * movementSpeed * Time.deltaTime);

            MyAnimator.SetFloat("speed", 1);
        }
        else
        {
            transform.Translate(Vector2.left * movementSpeed * Time.deltaTime);

            MyAnimator.SetFloat("speed", 1);
        }

        //if (Vector2.right.x > 0 && transform.position.x < rightEdge.position.x || Vector2.right.x < 0 && transform.position.x > leftEdge.position.x)
        //{
        //    MyAnimator.SetFloat("speed", 1);

        //    transform.Translate(Vector2.right * movementSpeed * Time.deltaTime);

        //    //Debug.Log("Andando");
        //}
        //else if (currentElfState is ElfPatrolState)
        //{
        //    ChangeDirection();
        //}
    }
Esempio n. 14
0
 public void HandleLayers()
 {
     if (IsAlive)
     {
         if (IsMoving)
         {
             ActivateLayer("WalkLayer");
             MyAnimator.SetFloat("x", Direction.x);
             MyAnimator.SetFloat("y", Direction.y);
         }
         else if (isAttackingShield)
         {
             ActivateLayer("AttackShieldLayer");
         }
         else if (isAttackingSword)
         {
             ActivateLayer("AttackSwordLayer");
         }
         else if (IsEnemyAttacking)
         {
             ActivateLayer("AttackEnemyLayer");
         }
         else
         {
             ActivateLayer("IdleLayer");
         }
     }
     else
     {
         ActivateLayer("DeathLayer");
     }
 }
Esempio n. 15
0
    private void UpdateDirection()
    {
        if (updateDirection)
        {
            Vector2 dir = Vector2.zero;

            if (MySpriteRenderer.sprite.name.Contains("up"))
            {
                dir = Vector2.up;
            }
            else if (MySpriteRenderer.sprite.name.Contains("down"))
            {
                dir = Vector2.down;
            }
            else if (MySpriteRenderer.sprite.name.Contains("left"))
            {
                dir = Vector2.left;
            }
            else if (MySpriteRenderer.sprite.name.Contains("right"))
            {
                dir = Vector2.right;
            }

            MyAnimator.SetFloat("x", dir.x);
            MyAnimator.SetFloat("y", dir.y);
            updateDirection = false;
        }
    }
Esempio n. 16
0
    private void HandleMovement(float horizontal)
    {
        if (MyRigidbody.velocity.y < 0)
        {
            MyAnimator.SetBool("land", true);
        }

        if (!Attack && !Slide && !Crouch || (OnGround || airControl))
        {
            MyRigidbody.velocity = new Vector2(horizontal * movementSpeed, MyRigidbody.velocity.y);
        }

        if (Jump && MyRigidbody.velocity.y == 0 && !Crouch)
        {
            MyRigidbody.AddForce(new Vector2(0, jumpForce));
        }

        ////player boundaries on X axis
        //if (transform.position.x <= -4.3f)
        //{
        //    transform.position = new Vector2(-4.3f, transform.position.y);
        //}
        //else if (transform.position.x >= 27.75f)
        //{
        //    transform.position = new Vector2(27.75f, transform.position.y);
        //}

        MyAnimator.SetFloat("speed", Mathf.Abs(horizontal));
    }
Esempio n. 17
0
    private void HandleMovement(float horizontal, float vertical)       // handles movement of the player and sets conditions so actions cannot be over lapped
    {
        if (IsFalling)
        {
            MyAnimator.SetBool("Land", true);
            gameObject.layer = 11;
        }

        if (!Attack && !Slide && (OnGround || airControl))
        {
            MyRigidBody.velocity = new Vector2(horizontal * movementSpeed, MyRigidBody.velocity.y);
        }

        if (Jump && MyRigidBody.velocity.y == 0 && !OnLadder)
        {
            MyRigidBody.AddForce(new Vector2(0, jumpforce));
        }

        if (OnLadder)
        {
            MyAnimator.speed     = vertical != 0 ? Mathf.Abs(vertical) : Mathf.Abs(horizontal);
            MyRigidBody.velocity = new Vector2(horizontal * climbSpeed, vertical * climbSpeed);
        }

        MyAnimator.SetFloat("speed", Mathf.Abs(horizontal));
    }
Esempio n. 18
0
    //When this function is called, it controls which animation is being used
    public void HandleLayers()
    {
        //Checks to see if there is any movement direction input
        if (IsAlive)
        {
            if (IsMoving)
            {
                //calls the ActivateLayer function to set the active layer to WalkLayer when keys are being pressed
                //as represented by the IsMoving Boolean being true
                ActivateLayer("WalkLayer");

                //Sets the Animation facing based on the keypress directions
                MyAnimator.SetFloat("x", Direction.x);
                MyAnimator.SetFloat("y", Direction.y);
            }
            else if (IsAttacking)
            {
                ActivateLayer("AttackLayer");
            }
            else
            {
                //calls the ActivateLayer function to set the active layer to IdleLayer when no keys are being pressed
                //as represented by the IsMoving Boolean being false
                ActivateLayer("IdleLayer");
            }
        }
        else
        {
            ActivateLayer("DeathLayer");
        }
    }
Esempio n. 19
0
    public void HandleLayers()
    {
        if (IsAlive)
        {
            if (IsMoving)
            {
                ActivateLayer("WalkLayer");

                MyAnimator.SetFloat("x", direction.x);
                MyAnimator.SetFloat("y", direction.y);
            }
            else if (isUsingSkill)
            {
                ActivateLayer("SkillLayer");
            }
            else if (isUsingHeal)
            {
                ActivateLayer("HealLayer");
            }
            else if (IsAttacking)
            {
                ActivateLayer("AttackLayer");
            }
            else
            {
                ActivateLayer("IdleLayer");
            }
        }
        else
        {
            ActivateLayer("DeathLayer");
        }
    }
Esempio n. 20
0
    private void HandleMovement(float horizontal)
    {
        if (IsFalling && gameObject.layer != 9)
        {
            gameObject.layer = 10;
            MyAnimator.SetBool("land", true);
        }
        //run
        if (!Attack && !Slide)
        {
            MyRigidbody.velocity = new Vector2(horizontal * movementSpeed, MyRigidbody.velocity.y);
        }

        if (OnGround && Jump)
        {
            Debug.Log(Jump);
            Debug.Log(OnGround);
            if (this.MyAnimator.GetCurrentAnimatorStateInfo(0).IsTag("idle"))
            {
                MyRigidbody.velocity = (new Vector2(0, 50 * (jumpForce / MyRigidbody.mass)));
            }
            else if (this.MyAnimator.GetCurrentAnimatorStateInfo(0).IsTag("run"))
            {
                MyRigidbody.velocity = (new Vector2(horizontal * movementSpeed, 50 * (jumpForce / MyRigidbody.mass)));
            }
        }
        MyAnimator.SetFloat("speed", Mathf.Abs(horizontal));
    }
Esempio n. 21
0
    /// <summary>
    /// Makes sure that the right animation layer is playing
    /// </summary>
    public void HandleLayers()
    {
        if (IsAlive)
        {
            //Checks if we are moving or standing still, if we are moving then we need to play the move animation
            if (IsMoving)
            {
                ActivateLayer("WalkLayer");

                //Sets the animation parameter so that he faces the correct direction
                MyAnimator.SetFloat("X", Direction.x);
                MyAnimator.SetFloat("Y", Direction.y);
            }
            else if (IsAttacking)
            {
                ActivateLayer("AttackLayer");
            }
            else
            {
                //Makes sure that we will go back to idle when we aren't pressing any keys.
                ActivateLayer("IdleLayer");
            }
        }
        else
        {
            ActivateLayer("DeathLayer");
        }
    }
Esempio n. 22
0
    private void HandleMovement(float horizontal)
    {
        if (MyRigidbody.velocity.y < 0)
        {
            MyAnimator.SetBool("land", true);
        }

        if (!Attack && !Slide && (OnGround || airControl))
        {
            MyRigidbody.velocity = new Vector2(horizontal * movementSpeed, MyRigidbody.velocity.y);
        }

        if (Input.GetKeyDown(KeyCode.UpArrow) && !OnGround && canDoubleJump)
        {
            MyRigidbody.AddForce(new Vector2(0, jumpForce));
            canDoubleJump = false;
        }
        else
        if (Input.GetKeyDown(KeyCode.UpArrow) && OnGround)
        {
            MyRigidbody.AddForce(new Vector2(0, jumpForce));
            canDoubleJump = true;
        }


        MyAnimator.SetFloat("speed", Mathf.Abs(horizontal)); // Seteaza parametrul speed al animatorului in 1 --> se activeaza animatia run
    }
Esempio n. 23
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));
    }
Esempio n. 24
0
    private void HandleMovement(float horizontal, float vertical)
    {
        if (isRunning)
        {
            movementSpeed = 5f;
        }
        else
        {
            movementSpeed = 2f;
        }

        if (IsFalling)
        {
            gameObject.layer = 11;
            MyAnimator.SetBool("land", true);
        }
        if (!Attack && !Slide && (OnGround || airControl))
        {
            MyRigidbody.velocity = new Vector2(horizontal * movementSpeed, MyRigidbody.velocity.y);
        }
        if (Jump && MyRigidbody.velocity.y == 0 && !OnLadder)
        {
            MyRigidbody.AddForce(new Vector2(0, jumpForce));
        }
        if (OnLadder)
        {
            MyAnimator.speed     = vertical != 0 ? Mathf.Abs(vertical) : Mathf.Abs(horizontal);
            MyRigidbody.velocity = new Vector2(horizontal * climbSpeed, vertical * climbSpeed);
        }

        MyAnimator.SetFloat("speed", Mathf.Abs(horizontal));
    }
Esempio n. 25
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);
        }
    }
Esempio n. 26
0
    //Moves the enemy
    public void Move()
    {
        //If the enemy is not attacking
        if (!Attack)
        {
            //in order the enemy does get out of the platform while following the player
            if ((GetDirection().x > 0 && transform.position.x < rightEdge.position.x) || (GetDirection().x < 0 && transform.position.x > leftEdge.position.x))
            {
                //Sets the speed to 1 to the player the run animation
                MyAnimator.SetFloat("speed", 1);

                //Moves the enemy in the correct direction
                transform.Translate(GetDirection() * (movementSpeed * Time.deltaTime));
            }
            else if (currentState is PatrolState)
            {
                ChangeDirection();
            }
            else if (currentState is RangedState)
            {
                Target = null;
                ChangeState(new IdleState());
            }
        }
    }
Esempio n. 27
0
 public void Move()
 {
     if (!Attack)
     {
         MyAnimator.SetFloat("Speed", 1);
         transform.Translate(GetDirection() * movementSpeed * (Time.deltaTime));
     }
 }
Esempio n. 28
0
    public void RunAway()
    {
        Vector3 moveDir = Player.Instance.transform.position - transform.position;

        transform.Translate(moveDir.normalized * movementSpeed * Time.deltaTime);

        MyAnimator.SetFloat("speed", 1);
    }
Esempio n. 29
0
 public void TakeControl(bool _control)
 {
     if (!_control)
     {
         MyAnimator.SetFloat("speed", 0);
     }
     canControl = _control;
 }
Esempio n. 30
0
 public void Move()
 {
     if (!Attack)
     {
         MyAnimator.SetFloat("speed", 1);
         transform.Translate(GetDirection() * (movementSpeed * Time.deltaTime), Space.World);
     }
 }