public override void ExecuteCommand(Command command, bool resetState)
    {
        TutorialPlayerCommand cmd = (TutorialPlayerCommand)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;

            // NEW CODE
            if (cmd.IsFirstExecution)
            {
                AnimatePlayer(cmd);

                state.pitch = cmd.Input.Pitch;

                // check if we should try to fire our weapon
                if (cmd.Input.aiming && cmd.Input.fire)
                {
                    FireWeapon(cmd);
                }
            }
        }
    }
    void AnimatePlayer(TutorialPlayerCommand cmd)
    {
        // FWD <> BWD movement
        if (cmd.Input.Forward ^ cmd.Input.Backward)
        {
            state.MoveZ = cmd.Input.Forward ? 1 : -1;
        }
        else
        {
            state.MoveZ = 0;
        }

        // LEFT <> RIGHT movement
        if (cmd.Input.Left ^ cmd.Input.Right)
        {
            state.MoveX = cmd.Input.Right ? 1 : -1;
        }
        else
        {
            state.MoveX = 0;
        }

        // JUMP
        if (_motor.jumpStartedThisFrame)
        {
            state.Jump();
        }
    }
 void FireWeapon(TutorialPlayerCommand cmd)
 {
     if (weapons[0].FireFrame + weapons[0].FireInterval <= BoltNetwork.ServerFrame)
     {
         weapons[0].FireFrame = BoltNetwork.ServerFrame;
         state.Fire();
     }
 }
    public override void SimulateController()
    {
        PollKeys(false);

        ITutorialPlayerCommandInput input = TutorialPlayerCommand.Create();

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

        // new lines
        input.aiming = _aiming;
        input.fire   = _fire;

        entity.QueueInput(input);
    }
Exemplo n.º 5
0
 public virtual void HitDetection(TutorialPlayerCommand cmd, BoltEntity entity)
 {
 }