private void Chase()
    {
        attackDetector.gameObject.SetActive(true);
        // move in direction of player
        if (playerReference.transform.position.x >= transform.position.x)
        {
            entityMovement.MoveInDirection(1);
        }
        else
        {
            entityMovement.MoveInDirection(-1);
        }

        GameObject objectHit = raycastHelper.CheckForObjectHits();

        if (objectHit != null)
        {
            if (objectHit.tag == "Ground")
            {
                entityMovement.Jump();
            }
        }
        else if (groundedController.GetIsGrounded() &&
                 raycastHelper.CheckForLedges() &&
                 playerReference.transform.position.y > transform.root.position.y)
        {
            entityMovement.Jump();
        }
    }
 private void Jump()
 {
     if (!_entityMovement.IsMoving)
     {
         _entityMovement.Jump();
         _animationHandler.JumpAnimationTrigger();
     }
 }
Beispiel #3
0
    // Update is called once per frame
    void Update()
    {
        moveDirectionX = 0f;

        // Player character actions
        if (playerHealth.GetCanAct())
        {
            moveDirectionX = Input.GetAxisRaw("Horizontal");

            if (Input.GetButtonDown("Jump"))
            {
                playerMovement.Jump();
            }
            if (Input.GetButtonUp("Jump"))
            {
                playerMovement.CutJumpHeight();
            }

            if (Input.GetButtonDown("Transform"))
            {
                //playerMovement.StopiAllMovement();
                transformationController.Transform();
            }

            if (Input.GetButtonDown("LightAttack"))
            {
                if (transformationController.GetIsInNormalForm())
                {
                    meleeAttack.Attack(ActionType.lightMelee);
                }
                else
                {
                    rangedAttack.Attack(ActionType.lightRanged);
                }
            }
            if (Input.GetButtonDown("HeavyAttack"))
            {
                if (transformationController.GetIsInNormalForm())
                {
                    meleeAttack.Attack(ActionType.heavyMelee);
                }
            }
        }

        playerMovement.MoveInDirection(moveDirectionX);

        // Interface controls
        if (Input.GetButtonDown("Cancel"))
        {
            screenManager.SetPauseMenuActive();
        }
    }
Beispiel #4
0
    // Update is called once per frame
    private void FixedUpdate()
    {
        if (path == null)
        {
            return;
        }

        if (stateMachine.currentState.stateName != "Play")
        {
            entityMovement.Move(0);
            return;
        }

        bool  isTarget           = false;
        float distanceToWaypoint = UpdateWaypoint();
        float distanceToTarget   = Vector3.Distance(rb2D.position, target.position);

        Vector2 offset;

        if (!reachedEndOfPath && distanceToWaypoint < distanceToTarget)
        {
            offset = (path.vectorPath[currentWaypoint] - transform.position).normalized;
        }
        else
        {
            isTarget = true;
            offset   = (target.position - transform.position).normalized;
        }

        float xAxis = Mathf.Sign(offset.x);

        entityMovement.Move(xAxis);

        if (!isTarget && offset.y > 0.4f)
        {
            entityMovement.Jump();
        }

        if (xAxis > 0f && direction == "left")
        {
            Flip("right");
        }

        if (xAxis < 0f && direction == "right")
        {
            Flip("left");
        }
    }
Beispiel #5
0
    // Update is called once per frame
    private void Update()
    {
        animator.SetFloat("HorizontalInput", Mathf.Abs(horizontalInput));

        if (stateMachine.currentState.stateName != "Play")
        {
            horizontalInput = 0f;
            return;
        }

        horizontalInput = Input.GetAxis("Horizontal");

        if (Input.GetButtonDown("Jump"))
        {
            entityMovement.Jump();
        }
    }
Beispiel #6
0
    void Update()
    {
        if (GameManager.instance.isPaused())
        {
            return;
        }
        var shakingAmount = Input.acceleration.magnitude;

        if (shakingAmount > 1.5)
        {
            Special();
        }

        //if pressing jump button, call jump method to toggle boolean
        if (Input.GetButtonDown("Jump"))
        {
            entityMovement.Jump();
        }

        if (isJumping)
        {
            entityMovement.Jump();
            isJumping = false;
        }

        float hVelocity = CrossPlatformInputManager.GetAxis("Horizontal");

        if (hVelocity == 0)
        {
            hVelocity = Input.GetAxis("Horizontal");
            animator.ResetTrigger("Walk");
        }

        if (hVelocity != 0)
        {
            animator.SetTrigger("Walk");
        }

        //Call the base movement module method to handle movement
        entityMovement.Movement(hVelocity);

        //If the shift button is pressed
        if (Input.GetKeyDown(KeyCode.LeftShift))
        {
            Shoot();
        }

        //If the control button is pressed
        if (Input.GetKeyDown(KeyCode.LeftControl))
        {
            Melee();
        }

        //Set attack collider to enabled for the attack duration
        if (attacking == true)
        {
            meleeCollider.enabled = true;
            if ((Time.time - lastAttack) > attackDuration)
            {
                attacking = false;
                animator.ResetTrigger("Attack");
                meleeCollider.enabled = false;
            }
        }
        else
        {
            meleeCollider.enabled = false;
        }

        //Make player temporarily invulnerable after taking damage
        //Achieved by changing alpha values of the sprite
        if (temporaryInvulnerable)
        {
            if (rend.material.color.a == 1f && Time.time > opacitySwitchTime)
            {
                opacitySwitchTime = Time.time + 0.25f;
                setAlpha(0.5f);
            }
            if (rend.material.color.a == .5f && Time.time > opacitySwitchTime)
            {
                opacitySwitchTime = Time.time + 0.25f;
                setAlpha(1.0f);
            }
            if (Time.time > temporaryInvulnerableTime + invulnTime)
            {
                temporaryInvulnerable = false;
                setAlpha(1.0f);
            }
        }

        UpdateStats();
    }
Beispiel #7
0
 void OnLand(EntityMovement entMove)
 {
     mJumpSpd *= 0.8f;
     entMove.Jump(mJumpSpd, false);
 }
Beispiel #8
0
 void OnLand(EntityMovement entMove)
 {
     if(mBounceSpeed == 0) {
         Release();
     }
     else {
         entMove.Jump(mBounceSpeed, false);
         mBounceSpeed *= bounceSpeedScaleDecay;
     }
 }