// Update is called once per frame void Update() { Vector2 input = new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical")); if (!animator.GetBool("isDashing") && !isTakingDamage) { if (controller.collisions.below) { animator.SetBool("isFalling", false); if (Input.GetButtonDown("Jump") && enableMoving) { velocity.y = maxJumpVelocity; sfx.PlayChawaJump(transform.position); } } else { if (!animator.GetBool(IsFalling)) { animator.SetBool(IsFalling, true); } } if (Input.GetButtonUp("Jump") && !isDrawning && enableMoving) { if (velocity.y > minJumpVelocity) { velocity.y = minJumpVelocity; } } velocity.x = input.x * moveSpeed; velocity.y += gravity * Time.deltaTime; if (velocity.x > 0 && enableMoving) { chawa.transform.localScale = new Vector3(chawaXScale, chawaYScale, 1); animator.SetBool(IsWalking, true); } else if (velocity.x < 0 && enableMoving) { chawa.transform.localScale = new Vector3(-chawaXScale, chawaYScale, 1); animator.SetBool(IsWalking, true); } else { animator.SetBool(IsWalking, false); } if (enableMoving) { controller.Move(velocity * Time.deltaTime, input); } if (controller.collisions.above || controller.collisions.below) { velocity.y = 0; } } else if (animator.GetBool("isDashing") && enableMoving) { if (!isDashing) { isDashing = true; if (controller.collisions.below) { dashAngle = 0; } if (input.x != 0 && input.y > 0) { dashAngle = 45; //gameObject.transform.rotation = Quaternion.Euler(0,0,45); } else if (input.x != 0 && input.y < 0) { dashAngle = -45; } else if (input.x == 0 && input.y > 0) { dashAngle = 90; } else if (input.x == 0 && input.y < 0) { dashAngle = 270; } else if (input.x != 0 && input.y == 0) { dashAngle = 0; } stopDashTime = Time.time + dashDuration; } velocity.x = Mathf.Cos(Mathf.PI * dashAngle / 180) * dashSpeed * Mathf.Sign(gameObject.transform.localScale.x) * Time.deltaTime; velocity.y = Mathf.Sin(Mathf.PI * dashAngle / 180) * dashSpeed * Time.deltaTime; controller.Move(velocity); if (Time.time > stopDashTime) { isDashing = false; animator.SetBool(IsDashing, false); gameObject.transform.rotation = Quaternion.Euler(0, 0, 0); } } else if (isTakingDamage) { velocity = new Vector3(knockback * knockbackDir * Time.deltaTime, knockback / 2 * Time.deltaTime); controller.Move(velocity); } }