private void OnClientUpdate(ClientRequest request) { // Move the player by the given delta. Move(request.Movement.ToVector3()); var positionNoOffset = transform.position - origin; // Send the update using the new position. var response = new ServerResponse { Position = positionNoOffset.ToIntAbsolute(), IncludesJump = request.IncludesJump, Timestamp = request.Timestamp, TimeDelta = request.TimeDelta }; var update = new ServerMovement.Update { Latest = response }; server.SendUpdate(update); if (Time.time - lastSpatialPositionTime > spatialPositionUpdateDelta) { var positionUpdate = new Position.Update { Coords = Coordinates.FromUnityVector(positionNoOffset) }; spatialPosition.SendUpdate(positionUpdate); lastSpatialPositionTime = Time.time; } }
private void OnRequestRespawn(HealthComponent.RequestRespawn.RequestResponder request) { // Reset the player's health. var healthUpdate = new HealthComponent.Update { Health = health.Data.MaxHealth }; health.Send(healthUpdate); // Move to a spawn point (position and rotation) var(spawnPosition, spawnYaw, spawnPitch) = SpawnPoints.GetRandomSpawnPoint(); var newLatest = new ServerResponse { Position = spawnPosition.ToIntAbsolute(), IncludesJump = false, Timestamp = serverMovement.Data.Latest.Timestamp, TimeDelta = 0 }; var serverMovementUpdate = new ServerMovement.Update { Latest = newLatest }; serverMovement.Send(serverMovementUpdate); // Update the spatial position on respawn. var spatialPositionUpdate = new Position.Update { Coords = spawnPosition.ToSpatialCoordinates() }; spatialPosition.Send(spatialPositionUpdate); transform.position = spawnPosition + spatial.Worker.Origin; var forceRotationRequest = new RotationUpdate { Yaw = spawnYaw.ToInt1k(), Pitch = spawnPitch.ToInt1k(), TimeDelta = 0 }; serverMovement.SendForcedRotation(forceRotationRequest); // Trigger the respawn event. health.SendRespawn(new Empty()); }
private void OnRequestRespawn(HealthComponent.RequestRespawn.ReceivedRequest request) { // Reset the player's health. var healthUpdate = new HealthComponent.Update { Health = health.Data.MaxHealth }; health.SendUpdate(healthUpdate); // Move to a spawn point (position and rotation) var(spawnPosition, spawnYaw, spawnPitch) = Respawning.SpawnPoints.GetRandomSpawnPoint(); var newLatest = new ServerResponse { Position = spawnPosition.ToVector3Int(), IncludesJump = false, Timestamp = serverMovement.Data.Latest.Timestamp, TimeDelta = 0 }; var serverMovementUpdate = new ServerMovement.Update { Latest = newLatest }; serverMovement.SendUpdate(serverMovementUpdate); transform.position = spawnPosition + spatial.Worker.Origin; var forceRotationRequest = new RotationUpdate { Yaw = spawnYaw.ToInt1k(), Pitch = spawnPitch.ToInt1k(), TimeDelta = 0 }; serverMovement.SendForcedRotationEvent(forceRotationRequest); // Trigger the respawn event. health.SendRespawnEvent(new Empty()); // Update spatial position in the next frame. StartCoroutine(SetSpatialPosition(spawnPosition)); }