Client prediction always incorrect

Options
Hey all, I'm just trying out Bolt, coming from a custom networking solution that used authoritative movement, and I'm having an issue where everytime I execute a command, it always ends up having an incorrect prediction in need of correction.

In my SimulateController I put a dubug log, and also in the execute command function, inside an if (resetState) statement. The log gets printed for both the exact same number of times.

My object's state has one property, Position. My command has one input, the movement axis, with one result for the position.

Does anybody have any clue why such a simple setup results in an incorrect prediction every time?

Comments

  • Stu
    Options
    public override void SimulateController()
        {
            IPlayerCommandInput input = PlayerCommand.Create();
            input.Move = new Vector3(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"), 0f);
    
            entity.QueueInput(input);
    
            Debug.Log("Take Input");
        }
    
        public override void ExecuteCommand(Command command, bool resetState)
        {
            PlayerCommand cmd = (PlayerCommand) command;
    
            if (resetState)
            {
                transform.position = cmd.Result.AvatarPos;
    
                Debug.Log("Correct State: ");
            }
            else
            {
                transform.position = transform.position + new Vector3(cmd.Input.Move.x, 0f, cmd.Input.Move.y) * 0.01f;
                cmd.Result.AvatarPos = transform.position;
    
                Debug.Log("Executed command");
            }
        }
    

    Added code
  • ramonmelo
    Options
    Hello @Stu ,

    Please, look at our docs: https://doc.photonengine.com/en-us/bolt/current/gameplay/commands

    You will find:
    The server then returns the result (the final position, speed, etc.) back to the player for a certain frame, who then essentially resets his position and other state back in time to the server’s on that frame.

    This happens for every Tick the server sends a Result back to the client. So, at every frame, for all your predicted entities, the client will reset to a known state in the past and replay the local commands, in order to get back to the "present".

    If, for example, you want to control when the Rollback will occurs, you can override the method described here: https://doc-api.photonengine.com/en/bolt/current/class_bolt_1_1_entity_behaviour.html#a12d49b4bdcba416a2444ef34a848d602
    Using this, you can signal Bolt that a reset is not needed, for example.

    --
    Ramon Melo
    Photon Bolt Team