void Update() { if (midAnimation) { transform.position = new Vector3(climbingDest.x, transform.position.y, 0f); return; } if (dead) { return; } if (feet.onGround && !onGroundLagger && currentVelocity >= deathSpeed) { dead = true; } onGroundLagger = feet.onGround; switch (currentState) { case State.Walking: if (inputHandler.leftStick.x_axis != 0f) { rb.velocity += new Vector2(inputHandler.leftStick.x_axis * horizontalAcceleration * Time.deltaTime, 0f); } if (rb.velocity.x > maximumHorizontalSpeed) { rb.velocity = new Vector2(maximumHorizontalSpeed, rb.velocity.y); } if (rb.velocity.x < -maximumHorizontalSpeed) { rb.velocity = new Vector2(-maximumHorizontalSpeed, rb.velocity.y); } if (rb.velocity.x > 0.1f && transform.localScale.x < 0 || rb.velocity.x < -0.1f && transform.localScale.x > 0) { transform.localScale = new Vector3(-transform.localScale.x, transform.localScale.y, transform.localScale.z); } if (inputHandler.leftTriggerAnalog.axis >= maxInputForJump && feet.onGround) { rb.velocity = new Vector2(rb.velocity.x, gravityCoEf * maxJumpSqrt); feet.onGround = false; soundHandler.Jump(); currentState = State.Jumping; } else if (inputHandler.leftTriggerAnalog.axis >= minInputForJump && feet.onGround) { rb.velocity = new Vector2(rb.velocity.x, gravityCoEf * minJumpSqrt + gravityCoEf * ((maxJumpSqrt - minJumpSqrt) / maxJumpSqrt) * ((inputHandler.leftTriggerAnalog.axis - minInputForJump) / (maxInputForJump - minInputForJump))); feet.onGround = false; soundHandler.Jump(); currentState = State.Jumping; } if (inputHandler.grab.enter) { if (hands.interactor != null) { interactorOffset = hands.interactor.transform.position - hands.transform.position; hands.interactor.body.constraints = RigidbodyConstraints2D.FreezeRotation; soundHandler.GrabbingLoopSFX(); currentState = State.Grabbing; } } break; case State.Jumping: if (feet.onGround) { currentState = State.Walking; } if (AbleToClimb()) { rb.velocity = Vector2.zero; currentState = State.Climbing; climbingDest = new Vector3(Mathf.Floor(transform.position.x) + (transform.localScale.x > 0f ? 1.3f : -0.3f), Mathf.Floor(transform.position.y) + 2.5f); StartClimb(); //rb.isKinematic = true; soundHandler.ClaraClimbingSFX(); } if (inputHandler.leftStick.x_axis != 0f) { rb.velocity += new Vector2(inputHandler.leftStick.x_axis * horizontalAcceleration * Time.deltaTime, 0f); } if (rb.velocity.x > maximumHorizontalSpeed) { rb.velocity = new Vector2(maximumHorizontalSpeed, rb.velocity.y); } if (rb.velocity.x < -maximumHorizontalSpeed) { rb.velocity = new Vector2(-maximumHorizontalSpeed, rb.velocity.y); } if (rb.velocity.x > 0.1f && transform.localScale.x < 0 || rb.velocity.x < -0.1f && transform.localScale.x > 0) { transform.localScale = new Vector3(-transform.localScale.x, transform.localScale.y, transform.localScale.z); } break; case State.Climbing: //if ((transform.position - climbingDest).magnitude > 0.6f) // transform.position = Vector3.Lerp(transform.position, climbingDest, 0.1f); //else //{ // rb.isKinematic = false; // currentState = State.Walking; //} transform.position = climbingDest; midAnimation = true; //rb.isKinematic = false; //currentState = State.Walking; break; case State.Grabbing: if (hands.interactor == null) { currentState = State.Walking; soundHandler.GrabStopSFX(); } if (!inputHandler.grab.held) { hands.interactor.body.constraints = RigidbodyConstraints2D.FreezeRotation | RigidbodyConstraints2D.FreezePositionX; currentState = State.Walking; soundHandler.GrabStopSFX(); } if (inputHandler.leftStick.x_axis != 0f) { rb.velocity += new Vector2(inputHandler.leftStick.x_axis * horizontalAcceleration * Time.deltaTime, 0f); } if (rb.velocity.x > maximumHorizontalSpeed) { rb.velocity = new Vector2(maximumHorizontalSpeed, rb.velocity.y); } if (rb.velocity.x < -maximumHorizontalSpeed) { rb.velocity = new Vector2(-maximumHorizontalSpeed, rb.velocity.y); } if (hands.interactor != null) { hands.interactor.body.velocity = new Vector2(rb.velocity.x, hands.interactor.body.velocity.y); } break; } currentVelocity = rb.velocity.magnitude; //soundHandler.walking = inputHandler.leftStick.x_axis != 0f && onGround; if (inputHandler.leftStick.x_axis != 0f && onGround) { soundHandler.ClaraWalkSFX(); } }