// Update is called once per frame void Update() { // Animation must happen before the Character is moved. characterAnimator.Animate(); float horizontalInput = Input.GetAxis("Horizontal"); float verticalInput = Input.GetAxis("Vertical"); float absHorizontalInput = Mathf.Abs(horizontalInput); float absVericalInput = Mathf.Abs(verticalInput); bool isInputingDirection = absHorizontalInput > 0f || absVericalInput > 0f; HandleChangeInRotation(horizontalInput, verticalInput, isInputingDirection); CalculateMovementDirection(absHorizontalInput, absVericalInput); HandleJump(); HandleGravity(); // Give momentum to the Character if (!isDrasticallyChangingDirection) { controller.Move(movementDirection * Time.deltaTime); } }
//****************************************************************** Update function ****************************************************************** // Update is called once per frame void Update() { if (playerFound) { //When the playerFound bool is true, the entity will track to the position of the player //CheckPlayerDirection(); print("YO"); transform.position = Vector2.MoveTowards(transform.position, (target.position + setEnemyDistance), enemyChaseSpeed * Time.deltaTime); //essentially make the target vector3 the target.position - buffer } if (enemyTempHealth <= 0) { HandleDestroy(); } characterAnimator.Animate(enemyController.getGrounded(), horizontalMove); }
//****************************************************************** Update function ****************************************************************** // Update is called once per frame void Update() { horizontalMove = Input.GetAxisRaw("Horizontal") * runSpeed; characterAnimator.Animate(controller.getGrounded(), horizontalMove); controller.Move(horizontalMove * Time.fixedDeltaTime, false /*, jump*/); /*if (Input.GetButtonDown("Jump")) * { * jump = true; * }*/ if ((Input.GetMouseButtonDown(0) || Input.GetKeyDown(KeyCode.Keypad1)) && !isAttacking) //Unity has their own stuff for mouse buttons too, might be good for eventual control customization { //Sets the attacking bool true, locking into a single attack at a time and preventing other animations isAttacking = true; //Calls DoAttack, which will set the hitbox collider active for a duration of time StartCoroutine(DoAttack()); characterAnimator.PlayMeleeAnimation(); soundManager.PlayJumpSound(); } }