Ejemplo n.º 1
0
    public override void SimulateController()
    {
        PollKeys(false);

        IGamePlayerCommandInput input = GamePlayerCommand.Create();

        input.Forward  = _forward;
        input.Backward = _backward;
        input.Left     = _left;
        input.Right    = _right;
        input.Jump     = _jump;
        input.Yaw      = _yaw;
        input.Pitch    = _pitch;

        entity.QueueInput(input);
    }
Ejemplo n.º 2
0
    public override void ExecuteCommand(Command command, bool resetState)
    {
        GamePlayerCommand cmd = (GamePlayerCommand)command;

        if (resetState)
        {
            // we got a correction from the server, reset (this only runs on the client)
            _motor.SetState(cmd.Result.Position, cmd.Result.Velocity, cmd.Result.IsGrounded, cmd.Result.JumpFrames);
        }
        else
        {
            // apply movement (this runs on both server and client)
            PlayerMotor.State motorState = _motor.Move(cmd.Input.Forward, cmd.Input.Backward, cmd.Input.Left, cmd.Input.Right, cmd.Input.Jump, cmd.Input.Yaw);

            // copy the motor state to the commands result (this gets sent back to the client)
            cmd.Result.Position   = motorState.position;
            cmd.Result.Velocity   = motorState.velocity;
            cmd.Result.IsGrounded = motorState.isGrounded;
            cmd.Result.JumpFrames = motorState.jumpFrames;
        }
    }