// Update is called once per frame void Update() { if (player.IsDead()) { return; } float movement = Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.LeftControl) ? 0 : Input.GetAxisRaw("Horizontal"); float airStay = Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.LeftControl) ? 0 : Input.GetAxisRaw("Vertical"); if (IsLanded) { if (Input.GetButtonDown("Jump")) { Vector2 jumpDir = transform.up.To2d().Rotate(30 * movement); myRig.AddForce(jumpDir * jumpingPower, ForceMode2D.Impulse); //myRig.AddForce(transform.right * movingDir * speed * myRig.mass, ForceMode2D.Impulse); //isLanded = false; jumpSoundPlayer.Play(); } if (Mathf.Abs(movement) > float.Epsilon) { gravityObject.Orbit(movement, speed * Time.deltaTime); //myRig.AddForce(transform.right * movingDir * speed * myRig.mass); idleTimer = 0; thinkingBubble.SetActive(false); } else { idleTimer += Time.deltaTime; if (idleTimer > 3f) { thinkingBubble.SetActive(true); } } } if (!player.IsFloating) { myRig.AddForce(transform.right * movement * myRig.mass * speed); myRig.AddForce(transform.up * airStay * myRig.mass * 5); } else { gravityObject.SetRotateDirection(movement); if (player.Energy > 20 && Input.GetButtonDown("Jump")) { myRig.AddForce(transform.up * myRig.mass * 10, ForceMode2D.Impulse); player.Energy -= 20; } } //Vector2 fallV = myRig.velocity.ComponentOn(gravityObject.GetGravity()); //Vector2 sideV = myRig.velocity - fallV; //if (sideV.magnitude > speed) { // sideV = sideV.SetMagnitude(speed); //}else{ // //sideV *= airFriction; //} //if (Input.GetKeyDown(KeyCode.T)){ //} //myRig.velocity = fallV + sideV; //if (Mathf.Abs(movingDir) > float.Epsilon){ // if (!gravityObject.IsFloating){ // gravityObject.Orbit(movingDir, speed * Time.deltaTime); // } //} animator.SetBool("IsGrounded", IsLanded); animator.SetBool("IsWalking", System.Math.Abs(movement) > float.Epsilon); }