// Update is called once per frame void Update() { input = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical")); wallDirX = (controller.collisions.left) ? -1 : 1; if (!controller.edgeDet.edge) { float targetVelocityX = input.x * moveSpeed; velocity.x = Mathf.SmoothDamp(velocity.x, targetVelocityX, ref velocityXsmoothing, (controller.collisions.below) ? accelerationTimeGrounded : accelerationTimeAirBorne); } HandleWallSliding(); if (controller.collisions.above || controller.collisions.below) { velocity.y = 0; } HandleInput(); if (!controller.edgeDet.edge) { velocity.y += gravity * Time.deltaTime; } animationController.stateInfo.velocity = velocity; animationController.stateInfo.input = input; if (controller.collisions.below) { animationController.stateInfo.grounded = true; } if (animationController.stateInfo.grounded || animationController.inBackJump) { animationController.Flip(input.x); } else { animationController.Flip(velocity.x); } //Debug.Log("velocity.x after damp: " + velocity.x); animationController.ContinueState(); controller.Move(velocity * Time.deltaTime, input); animationController.stateInfo.Reset(); }
protected override void ComputeVelocity() { gravity = (-2 * maxJumpHeight) / Mathf.Pow(timeToApex, 2); initialJumpVelocity = (2 * maxJumpHeight) / timeToApex; baseGravityModifier = gravity / Physics2D.gravity.y; if (grounded) { gravityModifier = baseGravityModifier; } Vector2 move = Vector2.zero; move.x = Input.GetAxis("Horizontal"); if (Input.GetButtonDown("Jump") && grounded) { velocity.y = initialJumpVelocity; } else if (Input.GetButtonUp("Jump")) { gravityModifier = lowGravityModifier; if (velocity.y > 0) { velocity.y = velocity.y * 0.5f; gravityModifier = fallingGravityModifier; } } if (move.x > 0.01f) { if (!animator.facingRight) { animator.Flip(); } } else if (move.x < -0.01f) { if (animator.facingRight) { animator.Flip(); } } if (grounded && Mathf.Abs(move.x) > .01f) { animator.StartAnimation("run"); } else if (!grounded && velocity.y < 0) { animator.StartAnimation("aimup"); } else if (!grounded && velocity.y > 0) { animator.StartAnimation("aimup"); } else { animator.StartAnimation("idle"); } targetVelocity = move * maxWalkSpeed; }