/// <remarks> /// This method gets invoked by the update timer every UpdatePeriodSeconds. /// Use it to send object updates to subscribers. The argument is always null. /// </remarks> private Task UpdateObservers(object arg) { if (IsValuesUpdated || IsMovementUpdated) { MovementUpdate movementUpdate = null; ValuesUpdate valuesUpdate = null; if (IsValuesUpdated) { valuesUpdate = BuildValuesUpdate(false); State.UpdateMask.Clear(); } if (IsMovementUpdated) { movementUpdate = BuildMovementUpdate(); IsMovementUpdated = false; } var objectUpdate = new ObjectUpdate(State.Id, State.TypeId, UpdateFlags, movementUpdate, valuesUpdate); observerManager.Notify(observer => observer.HandleObjectUpdate(State, objectUpdate)); OnPostUpdate(); } return(Task.CompletedTask); }
void AdvanceToNextMove() { elapsedLerpTime = 0; moves.Dequeue(); nextMove = moves.Peek(); realStartRotation = transform.rotation; realStartMovePos = transform.position; }
public void MovementUpdateMessage( string roadId, PlayerPosition playerPosition, IEnumerable <PlayerPosition> playerPositions) { AssertSerializable <MovementUpdate>(); var sut = new MovementUpdate(roadId, playerPosition, playerPositions); Assert.Equal(roadId, sut.RoadId); Assert.Equal(playerPosition, sut.PlayerPosition); Assert.Equal(playerPositions, sut.PlayerPositions); }
private void Move() { if (!CanMove) { return; } MovementUpdate?.Invoke(_moveDirection, _speed); var position = transform.position; _rigidbody.MovePosition(position + (_moveDirection * _speed * Time.fixedDeltaTime)); _ground.SetNormalAndPosition(Vector3.up, new Vector3(0f, position.y, 0f)); }
private void Movement() { if (!CanMove) { return; } var moveDirection = (_fixedAxisMovement ? Vector3.right : transform.right) * Input.GetAxis("Horizontal") + (_fixedAxisMovement ? Vector3.forward : transform.forward) * Input.GetAxis("Vertical"); if (moveDirection.magnitude >= 1f) { moveDirection = moveDirection.normalized; } MovementUpdate?.Invoke(moveDirection, _speed); _characterController.Move(moveDirection * (_speed * Time.deltaTime) + _gvelocity * Time.deltaTime); _ground.SetNormalAndPosition(Vector3.up, new Vector3(0f, transform.position.y, 0f)); }
private static MovementInfo ReadMovementStatusData(Packet packet, MovementUpdate movementUpdate, object index) { var moveInfo = new MovementInfo(); movementUpdate.Mover = packet.ReadPackedGuid128("MoverGUID", index); movementUpdate.MoveIndex = (int)packet.ReadUInt32("MoveIndex", index); movementUpdate.Position = moveInfo.Position = packet.ReadVector3("Position", index); movementUpdate.Orientation = moveInfo.Orientation = packet.ReadSingle("Orientation", index); movementUpdate.Pitch = packet.ReadSingle("Pitch", index); movementUpdate.StepUpStartElevation = packet.ReadSingle("StepUpStartElevation", index); var int152 = packet.ReadInt32("Int152", index); packet.ReadInt32("Int168", index); for (var i = 0; i < int152; i++) { packet.ReadPackedGuid128("RemoveForcesIDs", index, i); } packet.ResetBitReader(); moveInfo.Flags = (uint)packet.ReadBitsE <MovementFlag>("Movement Flags", 30, index); moveInfo.Flags2 = (uint)packet.ReadBitsE <MovementFlag2>("Extra Movement Flags", ClientVersion.AddedInVersion(ClientVersionBuild.V6_2_0_20173) ? 16 : 15, index); var hasTransport = packet.ReadBit("Has Transport Data", index); var hasFall = packet.ReadBit("Has Fall Data", index); packet.ReadBit("HasSpline", index); packet.ReadBit("HeightChangeFailed", index); packet.ReadBit("RemoteTimeValid", index); if (hasTransport) { var transport = movementUpdate.Transport = new(); transport.TransportGuid = packet.ReadPackedGuid128("Transport Guid", index); transport.Position = packet.ReadVector4("Transport Position", index); transport.Seat = (uint)packet.ReadSByte("Transport Seat", index); transport.MoveTime = (uint)packet.ReadInt32("Transport Time", index); packet.ResetBitReader(); var hasPrevMoveTime = packet.ReadBit("HasPrevMoveTime", index); var hasVehicleRecID = packet.ReadBit("HasVehicleRecID", index); if (hasPrevMoveTime) { transport.PrevMoveTime = packet.ReadUInt32("PrevMoveTime", index); } if (hasVehicleRecID) { transport.VehicleId = (int)packet.ReadUInt32("VehicleRecID", index); } } if (hasFall) { movementUpdate.FallTime = packet.ReadUInt32("Fall Time", index); movementUpdate.JumpVelocity = packet.ReadSingle("JumpVelocity", index); packet.ResetBitReader(); var bit20 = packet.ReadBit("Has Fall Direction", index); if (bit20) { packet.ReadVector2("Fall", index); packet.ReadSingle("Horizontal Speed", index); } } return(moveInfo); }
private void SaveMovementUpdate(MovementUpdate movementUpdate) { SaveInterpolationUpdate(ref positionInterpolationRoot, ref positionUpdates, ref timeDifferentialToPositionSender, new InterpolationData <Vector3>(movementUpdate.position.ToUnityVector(), movementUpdate.timestamp)); }
public MovementUpdate DeSerializeMovementUpdate(byte[] buffer, ref int offset, int length) { float size = 256; // TODO: This should be fetched from the Region.WidthInMetres of the region this message is for. float minHeight = -256; // TODO: I don't know where this should come from float maxHeight = 3 * 256; // TODO: I don't know where this should come from MovementUpdate update = new MovementUpdate(); int len = buffer[offset++]; int limit = offset + len; switch (len) { case 60 + 16: // pull out collision normal for avatar update.FootPlane = BinarySerializer.DeSerializeVector4(buffer, ref offset, limit); goto case 60; case 60: update.Position = BinarySerializer.DeSerializeVector3(buffer, ref offset, limit); update.Velocity = BinarySerializer.DeSerializeVector3(buffer, ref offset, limit); update.Acceleration = BinarySerializer.DeSerializeVector3(buffer, ref offset, limit); update.Rotation = BinarySerializer.DeSerializeQuaternion(buffer, ref offset, limit); // Theta update.AngularVelocity = BinarySerializer.DeSerializeVector3(buffer, ref offset, limit); // Omega break; case 32 + 16: // pull out collision normal for avatar update.FootPlane = BinarySerializer.DeSerializeVector4(buffer, ref offset, limit); goto case 32; case 32: // Values are UInt16 and needs to be quantized to floats update.Position = new Vector3( x: BinarySerializer.DeSerializeUInt16_Le(buffer, ref offset, limit).ToFloat(-0.5f * size, 1.5f * size), z: BinarySerializer.DeSerializeUInt16_Le(buffer, ref offset, limit).ToFloat(minHeight, maxHeight), // Handedness y: BinarySerializer.DeSerializeUInt16_Le(buffer, ref offset, limit).ToFloat(-0.5f * size, 1.5f * size)); update.Velocity = new Vector3( x: BinarySerializer.DeSerializeUInt16_Le(buffer, ref offset, limit).ToFloat(-size, size), z: BinarySerializer.DeSerializeUInt16_Le(buffer, ref offset, limit).ToFloat(-size, size), // Handedness y: BinarySerializer.DeSerializeUInt16_Le(buffer, ref offset, limit).ToFloat(-size, size)); update.Acceleration = new Vector3( x: BinarySerializer.DeSerializeUInt16_Le(buffer, ref offset, limit).ToFloat(-size, size), z: BinarySerializer.DeSerializeUInt16_Le(buffer, ref offset, limit).ToFloat(-size, size), // Handedness y: BinarySerializer.DeSerializeUInt16_Le(buffer, ref offset, limit).ToFloat(-size, size)); update.Rotation = new Quaternion( x: BinarySerializer.DeSerializeUInt16_Le(buffer, ref offset, limit).ToFloat(-1f, 1f), z: BinarySerializer.DeSerializeUInt16_Le(buffer, ref offset, limit).ToFloat(-1f, 1f), // Handedness y: BinarySerializer.DeSerializeUInt16_Le(buffer, ref offset, limit).ToFloat(-1f, 1f), w: BinarySerializer.DeSerializeUInt16_Le(buffer, ref offset, limit).ToFloat(-1f, 1f)); update.AngularVelocity = new Vector3( x: BinarySerializer.DeSerializeUInt16_Le(buffer, ref offset, limit).ToFloat(-size, size), z: BinarySerializer.DeSerializeUInt16_Le(buffer, ref offset, limit).ToFloat(-size, size), // Handedness y: BinarySerializer.DeSerializeUInt16_Le(buffer, ref offset, limit).ToFloat(-size, size)); break; case 16: // Values are UInt8 and needs to be quantized to floats update.Position = new Vector3( x: BinarySerializer.DeSerializeUInt8(buffer, ref offset, limit).ToFloat(-0.5f * size, 1.5f * size), z: BinarySerializer.DeSerializeUInt8(buffer, ref offset, limit).ToFloat(minHeight, maxHeight), // Handedness y: BinarySerializer.DeSerializeUInt8(buffer, ref offset, limit).ToFloat(-0.5f * size, 1.5f * size)); update.Velocity = new Vector3( x: BinarySerializer.DeSerializeUInt8(buffer, ref offset, limit).ToFloat(-size, size), z: BinarySerializer.DeSerializeUInt8(buffer, ref offset, limit).ToFloat(-size, size), // Handedness y: BinarySerializer.DeSerializeUInt8(buffer, ref offset, limit).ToFloat(-size, size)); update.Acceleration = new Vector3( x: BinarySerializer.DeSerializeUInt8(buffer, ref offset, limit).ToFloat(-size, size), z: BinarySerializer.DeSerializeUInt8(buffer, ref offset, limit).ToFloat(-size, size), // Handedness y: BinarySerializer.DeSerializeUInt8(buffer, ref offset, limit).ToFloat(-size, size)); update.Rotation = new Quaternion( x: BinarySerializer.DeSerializeUInt8(buffer, ref offset, limit).ToFloat(-1f, 1f), z: BinarySerializer.DeSerializeUInt8(buffer, ref offset, limit).ToFloat(-1f, 1f), // Handedness y: BinarySerializer.DeSerializeUInt8(buffer, ref offset, limit).ToFloat(-1f, 1f), w: BinarySerializer.DeSerializeUInt8(buffer, ref offset, limit).ToFloat(-1f, 1f)); update.AngularVelocity = new Vector3( x: BinarySerializer.DeSerializeUInt8(buffer, ref offset, limit).ToFloat(-size, size), z: BinarySerializer.DeSerializeUInt8(buffer, ref offset, limit).ToFloat(-size, size), // Handedness y: BinarySerializer.DeSerializeUInt8(buffer, ref offset, limit).ToFloat(-size, size)); break; } return(update); }