void FixedUpdate() { bool[] inputs = new bool[6]; inputs[0] = Input.GetKey(KeyCode.W); inputs[1] = Input.GetKey(KeyCode.A); inputs[2] = Input.GetKey(KeyCode.S); inputs[3] = Input.GetKey(KeyCode.D); inputs[4] = Input.GetKey(KeyCode.Space); inputs[5] = Input.GetMouseButton(0); yaw += Input.GetAxis("Mouse X") * sensitivityX; pitch += Input.GetAxis("Mouse Y") * sensitivityY; Quaternion rotation = Quaternion.Euler(pitch, yaw, 0); PlayerInputData inputData = new PlayerInputData(inputs, rotation, GameManager.Instance.LastRecievedServerTick - 1); transform.position = interpolation.CurrentData.Position; PlayerStateData nextStateData = playerLogic.GetNextFrameData(inputData, interpolation.CurrentData); interpolation.SetFramePosition(nextStateData); using (Message message = Message.Create((ushort)Tags.GamePlayerInput, inputData)) { ConnectionManager.Instance.Client.SendMessage(message, SendMode.Reliable); } }
public void UpdateState(PlayerStateData state) { State = (OTHER_PLAYER_STATE)state.state; isStrafing = state.isStrafing; TargetMovement = state.position; TargetRotation = state.rotation; }
public void ResetTo(PlayerStateData stateData) { CharacterController.enabled = false; transform.localPosition = stateData.Position; transform.localRotation = stateData.Rotation; CharacterController.enabled = true; }
public WeaveEssencePlayerState(PlayerInput input, PlayerBuildData buildData, PlayerStateData stateData, RecipeData recipes) { this.input = input; this.buildData = buildData; this.stateData = stateData; this.recipes = recipes; }
public void OnServerDataUpdate(PlayerStateData playerStateData) { if (isOwn) { while (reconciliationHistory.Any() && reconciliationHistory.Peek().Frame < GameManager.Instance.LastReceivedServerTick) { reconciliationHistory.Dequeue(); } if (reconciliationHistory.Any() && reconciliationHistory.Peek().Frame == GameManager.Instance.LastReceivedServerTick) { ReconciliationInfo info = reconciliationHistory.Dequeue(); if (Vector3.Distance(info.Data.Position, playerStateData.Position) > 0.05f) { List <ReconciliationInfo> infos = reconciliationHistory.ToList(); interpolation.CurrentData = playerStateData; transform.position = playerStateData.Position; transform.rotation = playerStateData.LookDirection; for (int i = 0; i < infos.Count; i++) { PlayerStateData u = playerLogic.GetNextFrameData(infos[i].Input, interpolation.CurrentData); interpolation.SetFramePosition(u); } } } } else { interpolation.SetFramePosition(playerStateData); } }
public void UpdateFromState(PlayerStateData s) { State = (OTHER_PLAYER_STATE)s.state; _isStrafing = s.isStrafing; TargetMovement = s.position; TargetRotation = s.rotation; }
public PlayerStateData PlayerUpdate() { if (inputs.Length > 0) { PlayerInputData input = inputs.First(); InputTick++; for (int i = 1; i < inputs.Length; i++) { InputTick++; for (int j = 0; j < input.Keyinputs.Length; j++) { input.Keyinputs[j] = input.Keyinputs[j] || inputs[i].Keyinputs[j]; } input.LookDirection = inputs[i].LookDirection; } currentPlayerStateData = PlayerLogic.GetNextFrameData(input, currentPlayerStateData); } PlayerStateDataHistory.Add(currentPlayerStateData); if (PlayerStateDataHistory.Count > 10) { PlayerStateDataHistory.RemoveAt(0); } transform.localPosition = currentPlayerStateData.Position; transform.localRotation = currentPlayerStateData.LookDirection; return(currentPlayerStateData); }
public PlaceObeliskPlayerState(PlayerInput input, PlayerBuildData buildData, PlayerStateData stateData) { this.buildData = buildData; this.input = input; this.stateData = stateData; buildBlocks = new List <GameObject>(); }
public void RegisterPlayer(NetworkInstanceId netId, string ruyiProfileId, string ruyiProfileName) { Debug.Log("Register Player: " + netId.ToString() + " | Host: " + isServer); // TODO: Get Profile Name var savePath = string.IsNullOrEmpty(ruyiProfileName) ? SAVEGAME_LOCATION : Path.Combine(ruyiProfileName, SAVEGAME_LOCATION); SaveGame saveGame; try { saveGame = mSaveLoad.Load <SaveGame>(RuyiNet.GetActivePersistentDataPath(), savePath); } catch (FileNotFoundException) { saveGame = new SaveGame(); } PlayerStateData playerState = new PlayerStateData { NetId = netId, ProfileId = ruyiProfileId, ProfileName = string.IsNullOrEmpty(ruyiProfileName) ? "Player " + netId : ruyiProfileName, Score = 0, CurrentStrength = saveGame.Strength, MaxStrength = saveGame.Strength }; if (mPlayerState != null) { mPlayerState.Add(playerState); } RpcUpdatePlayerColors(); }
public static PlayerState operator +(PlayerState p1, PlayerState p2) { //merge both collision state PlayerStateData mergedData = p1.stateData + p2.stateData; p1.stateData = mergedData; return(p1); }
public PlayerStateData GetNextFrameData(PlayerInputData input, PlayerStateData currentStateData) { bool w = input.Keyinputs[0]; bool a = input.Keyinputs[1]; bool s = input.Keyinputs[2]; bool d = input.Keyinputs[3]; bool space = input.Keyinputs[4]; Vector3 rotation = input.LookDirection.eulerAngles; gravity = new Vector3(0, currentStateData.Gravity, 0); Vector3 movement = Vector3.zero; if (w) { movement += Vector3.forward; } if (a) { movement += Vector3.left; } if (s) { movement += Vector3.back; } if (d) { movement += Vector3.right; } movement = Quaternion.Euler(0, rotation.y, 0) * movement; // Move towards the look direction. movement.Normalize(); movement = movement * walkSpeed; movement = movement * Time.fixedDeltaTime; movement = movement + gravity * Time.fixedDeltaTime; // The following code fixes character controller issues from unity. It makes sure that the controller stays connected to the ground by adding a little bit of down movement. CharacterController.Move(new Vector3(0, -0.001f, 0)); if (CharacterController.isGrounded) { if (space) { gravity = new Vector3(0, jumpStrength, 0); } } else { gravity -= new Vector3(0, gravityConstant, 0); } CharacterController.Move(movement); return(new PlayerStateData(currentStateData.Id, gravity.y, transform.localPosition, input.LookDirection)); }
PlayerStateData ResolveStaticCollision(FGRectCollider nextFrame, FGRectCollider other, Vector2 velocity) { PlayerStateData resolutionState = new PlayerStateData(); if (Collides(nextFrame, other)) { Vector2 overlap = CheckRectCollision(nextFrame.GetRect(), velocity, other.GetRect()); ResolveCollision(ref resolutionState, overlap); } return(resolutionState); }
internal void UpdatePlayerState(PlayerStateData playerState) { if (!isLocalPlayer) { interpolation.PushStateData(playerState); return; } if (history.Count == 0) { return; } // erstmal verwerfen wir alle inputs die bereits vom server authorisiert wurden while (history.Count > 0 && history.Peek().InputTick < playerState.InputTick) { history.Dequeue(); } if (history.Peek().InputTick != playerState.InputTick) { return; } var predictedState = history.Dequeue(); if ((predictedState.StateData.Position - playerState.Position).sqrMagnitude < reconciliationTolerance) { return; } //Debug.Log($"start reconciliation for frame {predictedState.InputTick}"); //Debug.Log($"predicted position: {predictedState.StateData.Position}\nserver position: {playerState.Position}"); // dann setzen wir den Spieler auf den letzten authorisierten Zustand interpolation.CurrentStateData = playerState; playerController.ResetTo(playerState); // dann wenden wir alle noch nicht authorisierten inputs wieder an if (history.Count != 0) { //Debug.Log($"applying {history.Count} inputs..."); var reconciliationInfos = history.ToArray(); foreach (var ri in reconciliationInfos) { //Debug.Log($"applying input {ri.InputTick}: {ri.InputData.MovementAxes}"); playerController.ResetTo(interpolation.CurrentStateData); var psd = playerController.GetNextFrameData(ri.InputData, interpolation.CurrentStateData); interpolation.PushStateData(psd); //Debug.Log($"moved from {interpolation.PreviousStateData.Position} to {interpolation.CurrentStateData.Position}"); } } }
public PlayerState(PlayerState playerState, PlayerInputState inputs) { stateData = new PlayerStateData(); stateData.Collisions = playerState.stateData.Collisions; stateData.FrameState = playerState.stateData.FrameState; stateData.velocity = playerState.stateData.velocity; _currentDirection = playerState.GetDirection(); HP = playerState.HP; nextActionDelay = playerState.nextActionDelay; inputState = inputs; }
//获取玩家数据 public PlayerStateData GetPlayerStateData(string playerId) { PlayerStateData data = null; if (!m_playerStateData.TryGetValue(playerId, out data)) { //初始化一个默认的 data = new PlayerStateData(playerId); m_playerStateData.Add(playerId, data); } return(data); }
public PlayerStateData GetNextFrameData(PlayerInputData inputData, PlayerStateData currentStateData) { var applyRotation = inputData.Inputs[1]; var movement = new Vector3(inputData.MovementAxes.x, 0, inputData.MovementAxes.y) * movementSpeed * Time.fixedDeltaTime; var lookDirection = new Vector3(inputData.RotationAxes.x, 0, inputData.RotationAxes.y); var rotation = applyRotation ? Quaternion.LookRotation(lookDirection, Vector3.up) : transform.rotation; CharacterController.Move(movement); transform.localPosition = new Vector3(transform.localPosition.x, 0, transform.localPosition.z); //Debug.Log($"GetNextFrameData for InputTick: {inputData.InputTick}, {inputData.MovementAxes} => {currentStateData.Position}, {transform.localPosition}"); return(new PlayerStateData(currentStateData.Id, inputData.InputTick, transform.localPosition, rotation)); }
public void Initialize(Vector3 position, ClientConnection clientConnection) { this.clientConnection = clientConnection; room = clientConnection.Room; Client = clientConnection.Client; this.clientConnection.Player = this; currentPlayerStateData = new PlayerStateData(Client.ID, 0, position, Quaternion.identity); InputTick = room.ServerTick; health = 100; var playerSpawnData = room.GetSpawnDataForAllPlayers(); using (Message m = Message.Create((ushort)Tags.GameStartDataResponse, new GameStartData(playerSpawnData, room.ServerTick))) { Client.SendMessage(m, SendMode.Reliable); } }
public static void LoadPlayerState() { PlayerStateData data = new PlayerStateData(); string filePath = GetPlayerStatePath(); Stream stream = null; try { stream = File.Open(filePath, FileMode.Open); BinaryFormatter bformatter = new BinaryFormatter(); bformatter.Binder = new VersionDeserializationBinder(); data = (PlayerStateData)bformatter.Deserialize(stream); PlayerController.LastCheckPoint_CurGrenadeCount = data.lastCheckPoint_CurGrenadeCount; PlayerController.LastCheckPoint_IsLvlCampPlayer = data.lastCheckPoint_IsLvlCampPlayer; PlayerController.LastCheckPoint_HaveSecGun = data.lastCheckPoint_HaveSecGun; PlayerController.LastCheckPoint_PrimGun = data.lastCheckPoint_PrimGun; PlayerController.LastCheckPoint_PrimGunCurBulletCount = data.lastCheckPoint_PrimGunCurBulletCount; PlayerController.LastCheckPoint_PrimGunCurMagCount = data.lastCheckPoint_PrimGunCurMagCount; PlayerController.LastCheckPoint_SecGun = data.lastCheckPoint_SecGun; PlayerController.LastCheckPoint_SecGunCurBulletCount = data.lastCheckPoint_SecGunCurBulletCount; PlayerController.LastCheckPoint_SecGunCurMagCount = data.lastCheckPoint_SecGunCurMagCount; PlayerController.LoadWasOK = true; } catch { PlayerController.LoadWasOK = false; //<Test> Debug.LogError("Loading player state error!!!"); //</Test> } finally { if (stream != null) { stream.Close(); } } }
public void world_updatePlayerStates(PlayerStateData plr) { if (Player_Self != null && plr.id == Player_Self.PlayerID) { Player_Self.Health = plr.currentHP; Player_Self.Energy = plr.currentEnergy; } else { foreach (PlayerData_Other player in PlayerList) { if (player.PlayerID == plr.id) { player.UpdateFromState(plr); break; } } } }
public static void SavePlayerState() { PlayerStateData data = new PlayerStateData(); data.lastCheckPoint_CurGrenadeCount = PlayerController.LastCheckPoint_CurGrenadeCount; data.lastCheckPoint_IsLvlCampPlayer = PlayerController.LastCheckPoint_IsLvlCampPlayer; data.lastCheckPoint_HaveSecGun = PlayerController.LastCheckPoint_HaveSecGun; data.lastCheckPoint_PrimGun = PlayerController.LastCheckPoint_PrimGun; data.lastCheckPoint_PrimGunCurBulletCount = PlayerController.LastCheckPoint_PrimGunCurBulletCount; data.lastCheckPoint_PrimGunCurMagCount = PlayerController.LastCheckPoint_PrimGunCurMagCount; data.lastCheckPoint_SecGun = PlayerController.LastCheckPoint_SecGun; data.lastCheckPoint_SecGunCurBulletCount = PlayerController.LastCheckPoint_SecGunCurBulletCount; data.lastCheckPoint_SecGunCurMagCount = PlayerController.LastCheckPoint_SecGunCurMagCount; string filePath = GetPlayerStatePath(); Stream stream = null; try { stream = File.Open(filePath, FileMode.Create); BinaryFormatter bformatter = new BinaryFormatter(); bformatter.Binder = new VersionDeserializationBinder(); bformatter.Serialize(stream, data); } catch { //<Test> Debug.LogError("Saving player state error!!!"); //</Test> } finally { if (stream != null) { stream.Close(); } } }
void FixedUpdate() { if (isOwn) { bool[] inputs = new bool[6]; inputs[0] = Input.GetKey(KeyCode.W); inputs[1] = Input.GetKey(KeyCode.A); inputs[2] = Input.GetKey(KeyCode.S); inputs[3] = Input.GetKey(KeyCode.D); inputs[4] = Input.GetKey(KeyCode.Space); inputs[5] = Input.GetMouseButton(0); if (inputs[5]) { GameObject go = Instantiate(shotPrefab); go.transform.position = interpolation.CurrentData.Position; go.transform.rotation = transform.rotation; Destroy(go, 1f); } yaw += Input.GetAxis("Mouse X") * sensitivityX; pitch += Input.GetAxis("Mouse Y") * sensitivityY; Quaternion rotation = Quaternion.Euler(pitch, yaw, 0); PlayerInputData inputData = new PlayerInputData(inputs, rotation, GameManager.Instance.LastReceivedServerTick - 1); transform.position = interpolation.CurrentData.Position; PlayerStateData nextStateData = playerLogic.GetNextFrameData(inputData, interpolation.CurrentData); interpolation.SetFramePosition(nextStateData); using (Message message = Message.Create((ushort)Tags.GamePlayerInput, inputData)) { ConnectionManager.Instance.Client.SendMessage(message, SendMode.Reliable); } reconciliationHistory.Enqueue(new ReconciliationInfo(GameManager.Instance.ClientTick, nextStateData, inputData)); } }
public override void Deserialize(NetworkReader reader) { playerCount = reader.ReadInt32(); try { for (int i = 0; i < playerCount; i++) { PlayerStateData player = new PlayerStateData(); player.name = reader.ReadString(); player.id = reader.ReadString(); player.position = reader.ReadVector3(); player.rotation = reader.ReadQuaternion(); player.isStrafing = reader.ReadBoolean(); player.state = reader.ReadInt32(); player.currentHP = reader.ReadSingle(); player.currentEnergy = reader.ReadSingle(); Data.Add(player); } } catch { } }
void ResolveCollision(ref PlayerStateData resolutionState, Vector2 overlap) { Vector2 pushBack = -overlap / Time.fixedDeltaTime; if (overlap.x > 0) { resolutionState.Collisions |= CollisionState.RIGHT; } if (overlap.x < 0) { resolutionState.Collisions |= CollisionState.LEFT; } if (overlap.y > 0) { resolutionState.Collisions |= CollisionState.TOP; } if (overlap.y < 0) { resolutionState.Collisions |= CollisionState.BOTTOM; } resolutionState.velocity += pushBack; }
public ReconciliationInfo(uint inputTick, PlayerStateData stateData, PlayerInputData inputData) { InputTick = inputTick; StateData = stateData; InputData = inputData; }
public void UpdateState(PlayerStateData data) { _velocity = data.velocity; }
public PlayerState(Direction direction) { stateData = new PlayerStateData(); _currentDirection = direction; stateData.velocity = Vector2.zero; }
public PlayerStateData LoadPlayerState() { PlayerStateData state = new PlayerStateData(); string[] dataArray = gameData.PlayerState.ToString().Split('\n'); string[] proArray = dataArray[1].Split(','); state.EXP = int.Parse(proArray[0]); state.Money = int.Parse(proArray[1]); state.IsWalk = proArray[2] == "0" ? false : true; state.Type = (PlayerType)int.Parse(proArray[3]); dataArray = playerTypeData.ToString().Split('\n'); for (int i = 0; i < dataArray.Length; i++) { proArray = dataArray[i].Split(','); if (state.Type.ToString() == proArray[0]) { state.BaseSTR = int.Parse(proArray[1]); state.BaseDEX = int.Parse(proArray[2]); state.BaseINT = int.Parse(proArray[3]); state.BaseCON = int.Parse(proArray[4]); state.BaseLUK = int.Parse(proArray[5]); } } return state; }
public override void Act(PlayerStateData data) { data.PlayerRigidBody2D.velocity = (data.CurrentTargetPosition - data.PlayerPosition).normalized * data.playerMoveSpeed.Value; }
public ExtractingPlayerState(PlayerInput playerInput, PlayerBuildData buildData, PlayerStateData stateData) { this.playerInput = playerInput; this.buildData = buildData; this.stateData = stateData; }
public ReconciliationInfo(uint frame, PlayerStateData data, PlayerInputData input) { Frame = frame; Data = data; Input = input; }
public AwaitBuildPlayerState(PlayerInput input, PlayerBuildData buildData, PlayerStateData stateData) { this.input = input; this.buildData = buildData; this.stateData = stateData; }