private void ApplyInputButtonBit(FPSInput input, string keyName, int bit) { if (Input.IsActionPressed(keyName)) { input.buttons |= bit; } }
// Super basic test public void ProcessMovement(FPSInput input, float delta) { debugSb.Clear(); ApplyRotations(); //Console.WriteLine($"Buttons {input.buttons} delta {delta}"); Vector3 inputDir = new Vector3(); if (input.isBitOn(FPSInput.BitMoveForward)) { inputDir.z -= 1; } if (input.isBitOn(FPSInput.BitMoveBackward)) { inputDir.z += 1; } if (input.isBitOn(FPSInput.BitMoveLeft)) { inputDir.x -= 1; } if (input.isBitOn(FPSInput.BitMoveRight)) { inputDir.x += 1; } float mouseMoveX = 0; // horizontal turn float mouseMoveY = 0; // verticla turn if (input.isBitOn(FPSInput.BitLookLeft)) { mouseMoveX += KEYBOARD_TURN_DEGREES_PER_SECOND; } if (input.isBitOn(FPSInput.BitLookRight)) { mouseMoveX -= KEYBOARD_TURN_DEGREES_PER_SECOND; } if (input.isBitOn(FPSInput.BitLookUp)) { mouseMoveY += KEYBOARD_TURN_DEGREES_PER_SECOND; } if (input.isBitOn(FPSInput.BitLookDown)) { mouseMoveY -= KEYBOARD_TURN_DEGREES_PER_SECOND; } yaw += mouseMoveX * delta; pitch += mouseMoveY * delta; // convert desired move to world axes Transform t = _body.GlobalTransform; Vector3 forward = t.basis.z; Vector3 left = t.basis.x; Vector3 runPush = Vector3.Zero; runPush.x += forward.x * inputDir.z; runPush.z += forward.z * inputDir.z; runPush.x += left.x * inputDir.x; runPush.z += left.z * inputDir.x; runPush = runPush.Normalized(); // calculate horizontal move independently. Vector3 horizontal = CalcVelocityQuakeStyle( velocity, runPush, MOVE_SPEED, delta, true); velocity.x = horizontal.x; velocity.z = horizontal.z; // Apply external push Vector3 prevPosition = t.origin; // Move! Vector3 moveResult = _body.MoveAndSlide(velocity); // record move info for next frame lastMove = _body.GlobalTransform.origin - prevPosition; lastDelta = delta; debugSb.Append($"Pitch {pitch}\nyaw {yaw}\n"); debugSb.Append($"Prev delta {lastDelta}\n"); debugSb.Append($"Prev move {lastMove}\n"); debugSb.Append($"Velocity {velocity}\n"); debugSb.Append($"Run push {runPush}\n"); debugSb.Append($"Move spd {MOVE_SPEED} accel {MOVE_ACCELERATION}\n"); }