// Update is called once per frame void Update() { if (Mathf.Abs(Input.GetAxis(PC2D.Input.HORIZONTAL)) > PC2D.Globals.INPUT_THRESHOLD) { _motor.normalizedXMovement = Input.GetAxis(PC2D.Input.HORIZONTAL); } else { _motor.normalizedXMovement = 0; } // Jump? if (Input.GetButtonDown(PC2D.Input.JUMP)) { _motor.Jump(); } _motor.jumpingHeld = Input.GetButton(PC2D.Input.JUMP); if (Input.GetAxis(PC2D.Input.VERTICAL) < -PC2D.Globals.FAST_FALL_THRESHOLD) { _motor.fallFast = true; } else { _motor.fallFast = false; } if (Input.GetButtonDown(PC2D.Input.DASH)) { _motor.Dash(); } }
void Dash() { if (dashCount > 0 && Input.GetKeyDown(KeyCode.Joystick1Button2)) { _motor.Dash(); dashCount--; } }
void Update() { motor.normalizedXMovement = Input.GetAxis(XMovementAxis); if (Input.GetAxis(JumpAxis) > 0.0f) { motor.Jump(); } if (Input.GetAxis(DashAxis) > 0.0f) { motor.Dash(); } }
// Update is called once per frame void Update() { // Jump? // If you want to jump in ladders, leave it here, otherwise move it down if (Input.GetButtonDown(PC2D.Input.JUMP)) { _motor.Jump(); _motor.DisableRestrictedArea(); } _motor.jumpingHeld = Input.GetButton(PC2D.Input.JUMP); // X axis movement if (Mathf.Abs(Input.GetAxis(PC2D.Input.HORIZONTAL)) > PC2D.Globals.INPUT_THRESHOLD) { _motor.normalizedXMovement = Input.GetAxis(PC2D.Input.HORIZONTAL); } else { _motor.normalizedXMovement = 0; } if (Input.GetAxis(PC2D.Input.VERTICAL) != 0) { bool up_pressed = Input.GetAxis(PC2D.Input.VERTICAL) > 0; if (Input.GetAxis(PC2D.Input.VERTICAL) < -PC2D.Globals.FAST_FALL_THRESHOLD) { _motor.fallFast = false; } } if (Input.GetAxisRaw(PC2D.Input.VERTICAL) == -1) { _motor.Drop(); } else if (Input.GetButtonDown(PC2D.Input.DASH)) { _motor.Dash(); } else if (Input.GetButtonDown(PC2D.Input.SLASH)) { _motor.Slash(); } }
// Update is called once per frame void Update() { // 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); } _motor.normalizedXMovement = PlayerMovement; /* // XY freedom movement * if (_motor.motorState == PlatformerMotor2D.MotorState.FreedomState) { * _motor.normalizedXMovement = Input.GetAxis(PC2D.Input.HORIZONTAL); * _motor.normalizedYMovement = Input.GetAxis(PC2D.Input.VERTICAL); * * return; // do nothing more * } * * * // X axis movement * if (Mathf.Abs(Input.GetAxis(PC2D.Input.HORIZONTAL)) > PC2D.Globals.INPUT_THRESHOLD) { * _motor.normalizedXMovement = Input.GetAxis(PC2D.Input.HORIZONTAL); * } else { * _motor.normalizedXMovement = 0; * } * * if (Input.GetAxis(PC2D.Input.VERTICAL) != 0) { * bool up_pressed = Input.GetAxis(PC2D.Input.VERTICAL) > 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 = Input.GetAxis(PC2D.Input.HORIZONTAL); || _motor.normalizedYMovement = Input.GetAxis(PC2D.Input.VERTICAL); || } || } ||} else if (Input.GetAxis(PC2D.Input.VERTICAL) < -PC2D.Globals.FAST_FALL_THRESHOLD) { || _motor.fallFast = false; ||}*/ if (CnInputManager.GetAxis("Fire1") > 0f) { _motor.Dash(); } }
// Update is called once per frame void Update() { // 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); } // JUMP? // If you want to jump in ladders, leave it here, otherwise move it down if (CrossPlatformInputManager.GetButtonDown(PC2D.Input.JUMP)) { _motor.Jump(); _motor.DisableRestrictedArea(); JumpCounter.instance.DiscountJump(); GameObject.Find("AudioManager").GetComponent <AudioManager>().Play("Jump"); } // ATACK // if (Input.GetButtonDown("Fire1")) // { // gameObject.GetComponent<PC2D.PlatformerAnimation2D>().Attack(); // } _motor.jumpingHeld = CrossPlatformInputManager.GetButton(PC2D.Input.JUMP); // XY freedom movement if (_motor.motorState == PlatformerMotor2D.MotorState.FreedomState) { _motor.normalizedXMovement = CrossPlatformInputManager.GetAxis(PC2D.Input.HORIZONTAL); _motor.normalizedYMovement = CrossPlatformInputManager.GetAxis(PC2D.Input.VERTICAL); return; // do nothing more } // X axis movement if (Mathf.Abs(CrossPlatformInputManager.GetAxis(PC2D.Input.HORIZONTAL)) > PC2D.Globals.INPUT_THRESHOLD) { _motor.normalizedXMovement = CrossPlatformInputManager.GetAxis(PC2D.Input.HORIZONTAL); } else { _motor.normalizedXMovement = 0; } // Y axis movement if (CrossPlatformInputManager.GetAxis(PC2D.Input.VERTICAL) != 0) { bool up_pressed = CrossPlatformInputManager.GetAxis(PC2D.Input.VERTICAL) > 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 = CrossPlatformInputManager.GetAxis(PC2D.Input.HORIZONTAL); _motor.normalizedYMovement = CrossPlatformInputManager.GetAxis(PC2D.Input.VERTICAL); } } } else if (CrossPlatformInputManager.GetAxis(PC2D.Input.VERTICAL) < -PC2D.Globals.FAST_FALL_THRESHOLD) { _motor.fallFast = false; } if (CrossPlatformInputManager.GetButtonDown(PC2D.Input.DASH)) { _motor.Dash(); GameObject.Find("AudioManager").GetComponent <AudioManager>().Play("Dash"); } }
// Update is called once per frame void Update() { // 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); } // Jump? // If you want to jump in ladders, leave it here, otherwise move it down if (Input.GetButtonDown(PC2D.Input.JUMP)) { _motor.Jump(); _motor.DisableRestrictedArea(); } _motor.jumpingHeld = Input.GetButton(PC2D.Input.JUMP); // XY freedom movement if (_motor.motorState == PlatformerMotor2D.MotorState.FreedomState) { _motor.normalizedXMovement = Input.GetAxis(PC2D.Input.HORIZONTAL); _motor.normalizedYMovement = Input.GetAxis(PC2D.Input.VERTICAL); return; // do nothing more } // X axis movement if (Mathf.Abs(Input.GetAxis(PC2D.Input.HORIZONTAL)) > PC2D.Globals.INPUT_THRESHOLD) { _motor.normalizedXMovement = Input.GetAxis(PC2D.Input.HORIZONTAL); } else { _motor.normalizedXMovement = 0; } if (Input.GetAxis(PC2D.Input.VERTICAL) != 0) { bool up_pressed = Input.GetAxis(PC2D.Input.VERTICAL) > 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 = Input.GetAxis(PC2D.Input.HORIZONTAL); _motor.normalizedYMovement = Input.GetAxis(PC2D.Input.VERTICAL); } } } else if (Input.GetAxis(PC2D.Input.VERTICAL) < -PC2D.Globals.FAST_FALL_THRESHOLD) { _motor.fallFast = false; } // 如果按下了 Shot 的 Input的話, if (Input.GetButtonDown(PC2D.Input.SHOT)) { //把現在忍者的水平跟垂直按壓位移當作參數傳遞 Vector2 pos = new Vector2(Input.GetAxis(PC2D.Input.HORIZONTAL), Input.GetAxis(PC2D.Input.VERTICAL)); //發射手�媦C _shooter.Shot(pos); } if (Input.GetButtonDown(PC2D.Input.DASH)) { _motor.Dash(); } }
// Checks for Movement Input and applies it to the motor private void HandleMovementInput() { if (bPlayerControlDisabled) { return; } // If movement is disabled, return if (bMovementDisabled) { motor.normalizedXMovement = 0; motor.normalizedYMovement = 0; return; } if (!bWallJumping) { // Horizontal Axis motor.normalizedXMovement = playerInput.GetAxis("Movement Horizontal"); // Vertical Axis motor.normalizedYMovement = playerInput.GetAxis("Movement Vertical"); } // Crouching if (playerInput.GetAxis("Movement Vertical") < -0.8f && Mathf.Abs(motor.normalizedXMovement) < 0.4f) { if (motor.motorState == PlatformerMotor2D.MotorState.OnGround) { motor.normalizedXMovement = 0; collisionShape = ePlayerCollisionShape.Crouch; bCrouching = true; } else { if (!bSliding) { collisionShape = ePlayerCollisionShape.Standard; } bCrouching = false; } } else { if (!bSliding) { collisionShape = ePlayerCollisionShape.Standard; } bCrouching = false; } // If on wall or corner and conditions for walljumping is met then enable walljumpready if (bOnWall || bOnCorner) { if ((bLastWallCollisionDirLeft && motor.normalizedXMovement >= 0.1f) || (!bLastWallCollisionDirLeft && motor.normalizedXMovement <= -0.1f)) { bWallJumpReady = true; } else { bWallJumpReady = false; } } else { bWallJumpReady = false; } // Jumping if (playerInput.GetButtonDown("Jump")) { if (playerInput.GetAxis("Movement Vertical") < -0.25f) { if (motor.motorState == PlatformerMotor2D.MotorState.OnGround) { bool ghostJump = GhostJump(); if (!ghostJump) { motor.Jump(); } } else { motor.Jump(); } } else { motor.Jump(); } } // Variable Jump Height motor.jumpingHeld = playerInput.GetButton("Jump"); // Dashing if (playerInput.GetButtonDown("Dash")) { if (motor.canDash) { if (motor.motorState != PlatformerMotor2D.MotorState.ClimbingCorner) { // If On Ground, Jumping or Falling if (motor.motorState == PlatformerMotor2D.MotorState.OnGround || motor.motorState == PlatformerMotor2D.MotorState.Jumping || motor.motorState == PlatformerMotor2D.MotorState.Falling) { // Check velocity and aim direction if (Mathf.Abs(motor.velocity.x) < 0.1f && motor.canDash) { // If aiming then set motor direction to aiming direction if (bAimState) { motor.facingLeft = v2PrevAimDiff.x >= 0 ? true : false; } } } // If Slide Method is Down + Dash if (GlobalSettings.iSlideInputMethod == 0) { if (playerInput.GetAxis("Movement Vertical") < -0.4f) { if (motor.motorState == PlatformerMotor2D.MotorState.OnGround) { collisionShape = ePlayerCollisionShape.Slide; bSliding = true; } } } motor.Dash(); if (onDash != null) { onDash(); } } } } // If Slide Input Method is set to Own Input if (GlobalSettings.iSlideInputMethod == 1) { if (playerInput.GetButtonDown("Slide")) { if (motor.canDash && motor.motorState == PlatformerMotor2D.MotorState.OnGround) { collisionShape = ePlayerCollisionShape.Slide; bSliding = true; motor.Dash(); if (onDash != null) { onDash(); } } } } // Walk if (!bOnWall && !bOnCorner) { if (playerInput.GetButton("Walk") || bForceWalk) { motor.normalizedXMovement = Mathf.Clamp(motor.normalizedXMovement, -0.25f, 0.25f); } } }
// Update is called once per frame void Update() { if (controlActivo) { /*if (Mathf.Abs(Input.GetAxis(PC2D.Input.HORIZONTAL)) > PC2D.Globals.INPUT_THRESHOLD) * { * _motor.normalizedXMovement = Input.GetAxis(PC2D.Input.HORIZONTAL); * if (_motor.normalizedXMovement > 0) * { * direccion = 1; * } * else * { * direccion = -1; * } * * } * else * { * _motor.normalizedXMovement = 0; * }*/ // movimiento automatico _motor.normalizedXMovement = 1 * modificador; // Jump? if (Input.GetButtonDown(PC2D.Input.JUMP)) { _motor.Jump(); } _motor.jumpingHeld = Input.GetButton(PC2D.Input.JUMP); if (Input.GetAxis(PC2D.Input.VERTICAL) < -PC2D.Globals.FAST_FALL_THRESHOLD) { _motor.fallFast = true; } else { _motor.fallFast = false; } if (Input.GetButtonDown(PC2D.Input.DASH)) { _motor.Dash(); } if (Input.GetButtonDown("Fire2")) { Vector2 centro = colisionador.bounds.center; Vector2 origen = new Vector2(centro.x + (colisionador.bounds.extents.x * direccion), centro.y); RaycastHit2D ataque = Physics2D.Raycast(origen, Vector2.right * direccion, 1, capaEnemigos); Vector2 destino = origen + (Vector2.right * direccion); animador.Play("Attack"); _motor.velocity = new Vector2(0, 0); if (ataque.collider != null) { ataque.collider.gameObject.GetComponent <CompEnemigo>().herir(); } } } }
void UpdateClient() { if (!isLocalPlayer) { pendingMoves = new Queue(); return; } if (Mathf.Abs(Input.GetAxis(PC2D.Input.HORIZONTAL)) > PC2D.Globals.INPUT_THRESHOLD) { //_motor.normalizedXMovement = Input.GetAxis(PC2D.Input.HORIZONTAL); _dx = Input.GetAxis(PC2D.Input.HORIZONTAL); } else if (Mathf.Abs( CrossPlatformInputManager.GetAxis(GameGlobals.LEFTJOYHORIZONTAL)) > GameGlobals.JOY_THRESHOLD) { //_motor.normalizedXMovement = // CrossPlatformInputManager.GetAxis(GameGlobals.LEFTJOYHORIZONTAL); _dx = CrossPlatformInputManager.GetAxis(GameGlobals.LEFTJOYHORIZONTAL); } else { //_motor.normalizedXMovement = 0; _dx = 0; } if (isClient) { _motor.normalizedXMovement = _dx; } else if (isServer) { RpcHorizontalMovement(_dx); } CmdHorizontalMovement(_dx); // Jump? if (Input.GetButtonDown(PC2D.Input.JUMP) || CrossPlatformInputManager.GetButtonDown("Jump")) { // _joystickRight.SetImage(false); if (isClient) { _motor.Jump(); } CmdDoJump(); } _motor.jumpingHeld = (Input.GetButton(PC2D.Input.JUMP) || CrossPlatformInputManager.GetButton("Jump")); if (Input.GetAxis(PC2D.Input.VERTICAL) < -PC2D.Globals.FAST_FALL_THRESHOLD || (CrossPlatformInputManager.GetAxis(GameGlobals.LEFTJOYVERTICAL) < -PC2D.Globals.FAST_FALL_THRESHOLD)) { if (isClient) { _motor.fallFast = true; } CmdFallFast(true); } else { if (isClient) { _motor.fallFast = false; } CmdFallFast(false); } if ((Mathf.Abs(CrossPlatformInputManager .GetAxis(GameGlobals.RIGHTJOYHORIZONTAL)) > GameGlobals.JOY_THRESHOLD) || (Mathf.Abs(CrossPlatformInputManager .GetAxis(GameGlobals.RIGHTJOYVERTICAL)) > GameGlobals.JOY_THRESHOLD)) { Vector2 joystick = new Vector2( CrossPlatformInputManager.GetAxis(GameGlobals.RIGHTJOYHORIZONTAL), CrossPlatformInputManager.GetAxis(GameGlobals.RIGHTJOYVERTICAL)); CmdFire(joystick, false); if (isClient) { Fire(joystick, false); } else if (isServer) { RpcFire(joystick, false); } } if (Input.GetButtonDown(PC2D.Input.FIRE)) { CmdFire(new Vector2(1.0f, 0.0f), true); if (isClient) { Fire(new Vector2(1.0f, 0.0f), true); } else if (isServer) { RpcFire(new Vector2(1.0f, 0.0f), true); } } if (Input.GetButtonDown(PC2D.Input.DASH)) { if (isClient) { _motor.Dash(); } CmdDoDash(); } CmdProvidePositionToServer(transform.position); }
void Update() { if (!_enableMove) { if (!_motor.frozen) { _motor.frozen = true; } return; } else { if (_motor.frozen) { _motor.frozen = false; } } // 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); } // Jump? // If you want to jump in ladders, leave it here, otherwise move it down if (Input.GetButtonDown(PC2D.Input.JUMP)) { _motor.Jump(); _motor.DisableRestrictedArea(); if (_motor.IsOnLadder()) { _motor.LadderAreaExit(); } } _motor.jumpingHeld = Input.GetButton(PC2D.Input.JUMP); // XY freedom movement if (_motor.motorState == PlatformerMotor2D.MotorState.FreedomState) { _motor.normalizedXMovement = Input.GetAxis(PC2D.Input.HORIZONTAL); _motor.normalizedYMovement = Input.GetAxis(PC2D.Input.VERTICAL); return; // do nothing more } // X axis movement if (Mathf.Abs(Input.GetAxis(PC2D.Input.HORIZONTAL)) > PC2D.Globals.INPUT_THRESHOLD) { _motor.normalizedXMovement = Input.GetAxis(PC2D.Input.HORIZONTAL); } else { _motor.normalizedXMovement = 0; } if (Input.GetAxis(PC2D.Input.VERTICAL) != 0) { bool up_pressed = Input.GetAxis(PC2D.Input.VERTICAL) > 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 = Input.GetAxis(PC2D.Input.HORIZONTAL); _motor.normalizedYMovement = Input.GetAxis(PC2D.Input.VERTICAL); } } } else if (Input.GetAxis(PC2D.Input.VERTICAL) < -PC2D.Globals.FAST_FALL_THRESHOLD) { _motor.fallFast = false; } if (Input.GetKeyDown(PC2D.Input.START_SLIDE)) { //m_Animator.SetTrigger("slide"); m_Animator.Play("PlayerSlide"); _motor.Dash(); } if (Input.GetKeyDown(PC2D.Input.WAVE_SWORD)) { _motor.Wave(); if (_motor.motorState == PlatformerMotor2D.MotorState.JumpWave) { m_Animator.SetTrigger("jumpWave"); } else { m_Animator.SetTrigger("wave"); } meleeAttack.gameObject.SetActive(true); } if (Input.GetKeyUp(PC2D.Input.WAVE_SWORD)) { meleeAttack.gameObject.SetActive(false); meleeAttack.DisableDamage(); } if (Input.GetKeyDown(PC2D.Input.THROW_DAGGER)) { _motor.Throw(); if (_motor.motorState == PlatformerMotor2D.MotorState.JumpThrow) { m_Animator.SetTrigger("jumpThrow"); } else { m_Animator.SetTrigger("throw"); } } }
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(); } }
// Update is called once per frame void Update() { // 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); } // Jump? // If you want to jump in ladders, leave it here, otherwise move it down if (haveJumped) //Input.GetButtonDown(PC2D.Input.JUMP)) { haveJumped = false; _motor.Jump(); _motor.DisableRestrictedArea(); } _motor.jumpingHeld = true; // jumping; // Input.GetButton(PC2D.Input.JUMP); // XY freedom movement if (_motor.motorState == PlatformerMotor2D.MotorState.FreedomState) { _motor.normalizedXMovement = horizontal; //Input.GetAxis(PC2D.Input.HORIZONTAL); _motor.normalizedYMovement = vertical; //Input.GetAxis(PC2D.Input.VERTICAL); return; // do nothing more } // X axis movement if (Mathf.Abs(horizontal) > PC2D.Globals.INPUT_THRESHOLD) { _motor.normalizedXMovement = horizontal; //Input.GetAxis(PC2D.Input.HORIZONTAL); } else { _motor.normalizedXMovement = 0; } // Y axis movement if (vertical != 0) //Input.GetAxis(PC2D.Input.VERTICAL) != 0) { bool up_pressed = vertical > 0; //Input.GetAxis(PC2D.Input.VERTICAL) > 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 = horizontal; //Input.GetAxis(PC2D.Input.HORIZONTAL); _motor.normalizedYMovement = vertical; //Input.GetAxis(PC2D.Input.VERTICAL); } } } else if (vertical < -PC2D.Globals.FAST_FALL_THRESHOLD) { _motor.fallFast = false; } if (dash) { dash = false; _motor.Dash(); } if (attack) { attack = false; gameObject.GetComponent <PC2D.PlatformerAnimation2D>().Attack(); } }