//Le server et le client execute cette fonction public override void ExecuteCommand(Command command, bool resetState) { PlayerCommandInput cmd = (PlayerCommandInput)command; if (resetState) { _playerMotor.SetState(cmd.Result.Position, cmd.Result.Rotation); } else { PlayerMotor.State motorState = new PlayerMotor.State(); //Quand on est le server if (!entity.HasControl) { motorState = _playerMotor.ExecuteCommand( cmd.Input.Forward, cmd.Input.Backward, cmd.Input.Left, cmd.Input.Right, cmd.Input.Jump, cmd.Input.Yaw, cmd.Input.Pitch); _playerWeapons.ExecuteCommand(cmd.Input.Fire, cmd.Input.Scope, cmd.Input.Reload, cmd.ServerFrame % 1024); } cmd.Result.Position = motorState.position; cmd.Result.Rotation = motorState.rotation; } }
public override void ExecuteCommand(Command command, bool resetState) { PlayerCommand cmd = (PlayerCommand)command; if (resetState) { _playerMotor.SetState(cmd.Result.Position, cmd.Result.Rotation); } else { PlayerMotor.State motorState = new PlayerMotor.State(); if (!entity.HasControl) { motorState = _playerMotor.ExecuteCommand( cmd.Input.Forward, cmd.Input.Backward, cmd.Input.Left, cmd.Input.Right, cmd.Input.Yaw, cmd.Input.Pitch); } cmd.Result.Position = motorState.position; cmd.Result.Rotation = motorState.rotation; } }
public override void ExecuteCommand(Command command, bool resetState) { TicTacCommand cmd = (TicTacCommand)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.Grounded, 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.Grounded = motorState.isGrounded; cmd.Result.JumpFrames = motorState.jumpFrames; if (cmd.IsFirstExecution) { //AnimatePlayer(cmd); // set state pitch state.Pitch = cmd.Input.Pitch; // check if we should try to fire our weapon if (cmd.Input.Aiming && cmd.Input.Fire) { FireWeapon(cmd); } } } }
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; } }
// Executes on both the controller (usually client) and owner (usually server) public override void ExecuteCommand(Bolt.Command command, bool resetState) { PlayerCommand cmd = (PlayerCommand)command; if (resetState) { // There was 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 (both server + client) PlayerMotor.State motorState = _motor.Move(cmd.Input.Forward, cmd.Input.Backward, cmd.Input.LeftStrafe, cmd.Input.RightStrafe, cmd.Input.Jump, cmd.Input.Yaw, cmd.Input.Pitch); // copy motor state to the command's result (client) cmd.Result.Position = motorState.position; cmd.Result.Velocity = motorState.velocity; cmd.Result.IsGrounded = motorState.isGrounded; cmd.Result.JumpFrames = motorState.jumpFrames; } }