// Update is called once per frame void Update() { bool isIdle = true; // This sets the correct jump status when the player without jumping enters on free fall state. // Also corrects a sprite animation flickering when walking because the animation starts again // constantly after jump.resetStatus() if (exitedFromScenery && !jump.isJumping()) { ChipmunkSegmentQueryInfo qinfo; // check if there is no shape below us Vector2 end = body.position + queryOffset; Chipmunk.SegmentQueryFirst(body.position, end, collisionLayersSkip, collisionGroupSkip, out qinfo); // if no handler it means no hit if (System.IntPtr.Zero == qinfo._shapeHandle) { jump.reset(); // set state as if were jumping } } // jump if (Gamepad.Instance.isA()) { walk.stop(); jump.jump(lightJumpVelocity); // apply gain jump power. Only once per jump (handled in Jump component) if (Gamepad.Instance.isHardPressed(EnumButton.A)) { jump.applyGain(gainJumpFactor); } isIdle = false; } // power up action if (powerUp != null && powerUp.ableToUse()) { powerUp.action(gameObject); } // walk if (Gamepad.Instance.isLeft()) { // is speed up button being pressed? if (Gamepad.Instance.isB()) { walk.setGain(walk.speedUpFactor); } else { walk.setGain(1f); } walk.walk(-walkVelocity); fireDir = leftFireDir; } else if (Gamepad.Instance.isRight()) { // is speed up button being pressed? if (Gamepad.Instance.isB()) { walk.setGain(walk.speedUpFactor); } else { walk.setGain(1f); } walk.walk(walkVelocity); fireDir = rightFireDir; } if (walk.isWalking()) { isIdle = false; } // crouch if (Gamepad.Instance.isDown()) { crouch.crouch(); isIdle = false; } else { crouch.noCrouch(); } // look upwards/downwards if (!jump.isJumping()) { if (Gamepad.Instance.isUp()) { lookDirections.lookUpwards(); isIdle = false; } else { lookDirections.restore(); } } else { lookDirections.lockYWhenJumping(); } // finally only if not doing any action then set idle state if (isIdle) { idle.setIdle(false); } }
// Update is called once per frame void Update() { // this set the correct jump status when the player without jumping enters on free fall state // and also correct a sprite animation flickering when walking because the animation starts again // constantly after jump.resetStatus() if (exitedFromScenery && !jump.IsJumping()) { // check if there is no shape below us ChipmunkSegmentQueryInfo qinfo; Vector2 end = body.position + queryOffset; Chipmunk.SegmentQueryFirst(body.position, end, collisionLayers, collisionGroupSkip, out qinfo); // if no handler it means no hit if (System.IntPtr.Zero == qinfo._shapeHandle) { // set state as if were jumping jump.resetStatus(); } } bool isIdle = true; // jump if (Gamepad.isA() || Input.GetButton("Jump")) { walk.stopWalking(); // it resets walk behavior jump.jump(lightJumpVelocity); // apply gain jump power. Only once per jump (handled in Jump component) if (Gamepad.isHardPressed(EnumButton.A)) { jump.applyGain(gainJumpFactor); } isIdle = false; } // power up action if (powerUp != null && powerUp.ableToUse()) { powerUp.action(gameObject); } // move walk.enableWalking(); if (Gamepad.isLeft() || Input.GetAxis("Horizontal") < -0.1f) { walk.walk(-walkVelocity); fireDir = leftFireDir; isIdle = false; // enable move speed after a wall collision if intended moving direction changes if (signCollision > 0f) { restoreWalkVel(); } } else if (Gamepad.isRight() || Input.GetAxis("Horizontal") > 0.1f) { walk.walk(walkVelocity); fireDir = rightFireDir; isIdle = false; // enable move speed after a wall collision if intended moving direction changes if (signCollision < 0f) { restoreWalkVel(); } } else { // if no movement input then set correct internal status walk.stopWalking(); } // crouch if (Gamepad.isDown() || Input.GetAxis("Vertical") < -0.1f) { crouch.crouch(); isIdle = false; } else { crouch.noCrouch(); } // look upwards if (!jump.IsJumping()) { if (Gamepad.isUp() || Input.GetAxis("Vertical") > 0.1f) { lookUpwards.lookUpwards(); isIdle = false; } else { lookUpwards.restore(); } } else { lookUpwards.lockYWhenJumping(); } // finally only if no doing any action then set idle state if (isIdle) { idle.setIdle(false); } }