Server Moves Both Self and Client (Authoritative Movement Tutorial)

Options
Gleech
Gleech
edited August 2022 in Photon Bolt

I'm trying to follow the Authoritative Movement tutorial. I've re-read my code about a hundred times and I have everything copied line-for-line. However, when I connect to a server, it seems as though the client's character is also being controlled by the server.


(Left side is the server, right side is the client. When the cursor is over that side it's controlling it)

I really have no clue why this is happening. I'd share my code but it's practically identical to the code that's in the tutorial, with the exception of some of my movement code (I don't have jumping in my game, so some of the input parameters are not the same.)

public class PlayerController : EntityBehaviour<ISaucerState>
{
    private PlayerMovement playerMovement;

    private float forwardInput;
    private float rightInput;


    private void Awake()
    {
        playerMovement = GetComponent<PlayerMovement>();
    }


    public override void Attached()
    {
        state.SetTransforms(state.SaucerTransform, transform);
    }


    public override void SimulateController()
    {
        PollKeys();


        ISaucerPlayerCommandInput input = SaucerPlayerCommand.Create();


        input.Forward = forwardInput;
        input.Right = rightInput;


        entity.QueueInput(input);
       
    }
    public override void ExecuteCommand(Command command, bool resetState)
    {
        SaucerPlayerCommand cmd = (SaucerPlayerCommand)command;


        if (resetState)
        {
            playerMovement.SetState(cmd.Result.Position, cmd.Result.Velocity, cmd.Result.IsGrounded);
        }
        else
        {
            PlayerMovement.State state = playerMovement.Move(forwardInput, rightInput);


            cmd.Result.Position = state.position;
            cmd.Result.Velocity = state.velocity;
            cmd.Result.IsGrounded = state.isGrounded;
        }
    }


    private void Update()
    {
        PollKeys();
    }

    private void PollKeys()
    {
        rightInput = Input.GetAxis("Horizontal");
        forwardInput = Input.GetAxis("Vertical");
    }
}

My "PlayerMovement" class is very similar to the "PlayerMotor" class, just with some added stuff to simulate acceleration.

Can anyone lend any advice? Is there some setting I overlooked on the prefab or something?

Thanks!

Best Answer

  • Gleech
    Gleech
    Answer ✓
    Options

    Finally found it.

    PlayerMovement.State state = playerMovement.Move(forwardInput, rightInput);
    

    was supposed to be:

    PlayerMovement.State state = playerMovement.Move(cmd.Input.Forward, cmd.Input.Right);
    

Answers

  • Gleech
    Gleech
    Answer ✓
    Options

    Finally found it.

    PlayerMovement.State state = playerMovement.Move(forwardInput, rightInput);
    

    was supposed to be:

    PlayerMovement.State state = playerMovement.Move(cmd.Input.Forward, cmd.Input.Right);