private void UpdateWithController() { // use last state to restore some ladder specific values if (_motor.motorState != PlatformerMotor2D.MotorState.FreedomState) { // try to restore, sometimes states are a bit messy because change too much in one frame FreedomStateRestore(_motor); } //if (_motor.IsGrounded() && _motor.jumpHeight != defaultJumpHeight) //{ // _motor.jumpHeight = defaultJumpHeight; //} // Jump? // If you want to jump in ladders, leave it here, otherwise move it down if (InputManager.ActiveDevice.Action1.WasPressed) { if (hasNotMovedYet) { hasNotMovedYet = false; isStartingToMove = true; } } if (_motor.normalizedXMovement == 0f && InputManager.ActiveDevice.Direction.Down.IsPressed) { isChargingJump = true; } if (InputManager.ActiveDevice.Direction.Down.WasReleased) { isChargingJump = false; } if (InputManager.ActiveDevice.Action1.WasPressed) { if (hasNotMovedYet) { hasNotMovedYet = false; isStartingToMove = true; } if (InputManager.ActiveDevice.Direction.Down.IsPressed && !isCarryingItem) { _motor.jumpHeight = rechargedJumpHeight; _motor.Jump(); _motor.DisableRestrictedArea(); _motor.jumpHeight = defaultJumpHeight; } else { _motor.Jump(); _motor.DisableRestrictedArea(); } audioSource.PlayOneShot(jumpClip); timeChargingJump = 0f; isChargingJump = false; } //_motor.jumpingHeld = Input.GetButton(PC2D.Input.JUMP); // XY freedom movement if (_motor.motorState == PlatformerMotor2D.MotorState.FreedomState) { _motor.normalizedXMovement = InputManager.ActiveDevice.Direction.X; _motor.normalizedYMovement = InputManager.ActiveDevice.Direction.Y; return; // do nothing more } // X axis movement if (Mathf.Abs(InputManager.ActiveDevice.Direction.X) > PC2D.Globals.INPUT_THRESHOLD) { if (hasNotMovedYet) { hasNotMovedYet = false; isStartingToMove = true; } if (!isStartingToMove) { _motor.normalizedXMovement = InputManager.ActiveDevice.Direction.X; if (!audioSource.isPlaying && _motor.IsGrounded()) { audioSource.clip = walkClip; audioSource.Play(); } } } else { _motor.normalizedXMovement = 0; } if (InputManager.ActiveDevice.Direction.Y != 0) { if (hasNotMovedYet) { hasNotMovedYet = false; isStartingToMove = true; } bool up_pressed = InputManager.ActiveDevice.Direction.Y > 0; if (_motor.IsOnLadder()) { if ( (up_pressed && _motor.ladderZone == PlatformerMotor2D.LadderZone.Top) || (!up_pressed && _motor.ladderZone == PlatformerMotor2D.LadderZone.Bottom) ) { // do nothing! } // if player hit up, while on the top do not enter in freeMode or a nasty short jump occurs else { // example ladder behaviour _motor.FreedomStateEnter(); // enter freedomState to disable gravity _motor.EnableRestrictedArea(); // movements is retricted to a specific sprite bounds // now disable OWP completely in a "trasactional way" FreedomStateSave(_motor); _motor.enableOneWayPlatforms = false; _motor.oneWayPlatformsAreWalls = false; // start XY movement _motor.normalizedXMovement = InputManager.ActiveDevice.Direction.X; _motor.normalizedYMovement = InputManager.ActiveDevice.Direction.Y; } } } else if (InputManager.ActiveDevice.Direction.Y < -PC2D.Globals.FAST_FALL_THRESHOLD) { if (hasNotMovedYet) { hasNotMovedYet = false; isStartingToMove = true; } _motor.fallFast = false; } if (InputManager.ActiveDevice.Action2.WasPressed && !isCarryingItem) { _motor.Dash(); if (hasNotMovedYet) { hasNotMovedYet = false; isStartingToMove = true; } } if (InputManager.ActiveDevice.Action3.WasPressed && isInItem) { Carrying(); } if (InputManager.ActiveDevice.Action3.WasReleased && isCarryingItem) { NotCarrying(); } }