private void PlayAnimation() { DummyAnimator.SetBool("IsGrounded", isGrounded); DummyAnimator.SetFloat("HSpeed", inputDir.magnitude); DummyAnimator.SetFloat("VSpeed", velocityY); if (Input.GetButtonDown("Fire1") && isGrounded && Time.time >= timer) { if (CurrentPaint.Amount <= 0) { return; } DummyAnimator.SetTrigger("Attack"); timer = Time.time + attackTimer; } }
//---- Problems to solve ---- //check prev cam & input state for rotation optimizing! //input manager settings, eliminating slippery feel & etc. (GetAxisRaw do not affected by input manager settings!) //split input logic from controller logic? private void Update() { if (DummyAnimator.GetCurrentAnimatorStateInfo(0).IsName("Attack")) { return; } inputDir = new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical")) * maxSpeed; inputDir = Vector2.ClampMagnitude(inputDir, maxSpeed); //clamping on air & ground, not affecting jump height (inputDir is separate from jump value) isGrounded = CheckGround(); if (isGrounded) { isJumping = false; velocityY = 0; if (Input.GetButtonDown("Jump")) { velocityY = jumpSpeed; isJumping = true; } beforeFall = inputDir; } else { float rotation = Mathf.Atan2(inputDir.x, inputDir.y) * Mathf.Rad2Deg + camTransform.rotation.eulerAngles.y; targetRotation = Quaternion.Euler(0, rotation, 0); Vector3 target = targetRotation * Vector3.forward; if (Vector3.Angle(transform.forward.normalized, target.normalized) >= deadAngle) { inputDir = beforeFall * slowDownFactor; } } CalculateRotation(); velocityY -= gravity * Time.deltaTime * ((velocityY < 0) ? fallMultiplier : 1); //gravity applied per second Vector3 targetMove = targetRotation * Vector3.forward * inputDir.magnitude + Vector3.up * velocityY; controller.Move(targetMove * Time.deltaTime); //movement per second PlayAnimation(); }