public void RigidbodyUpdate(Packet packet) { Message_RigidbodyUpdate rigidbodyUpdate = (Message_RigidbodyUpdate)((PacketSingle)packet).message; //Debug.Log($"Rigidbody Update\nOur Network ID = {networkUID} Packet Network ID = {rigidbodyUpdate.networkUID}"); if (rigidbodyUpdate.networkUID != networkUID) { return; } targetPosition = VTMapManager.GlobalToWorldPoint(rigidbodyUpdate.position); rb.velocity = rigidbodyUpdate.velocity.toVector3; rb.angularVelocity = rigidbodyUpdate.angularVelocity.toVector3; transform.rotation = Quaternion.Euler(rigidbodyUpdate.rotation.toVector3); //Angular Velocity doesn't seem to be working so I'm just setting the rotation. if (Vector3.Distance(transform.position, targetPosition) > positionThreshhold) { Debug.Log("Outside of thresh hold, moving " + gameObject.name); transform.position = targetPosition; } else { //Debug.Log($"Updating Position of UID {networkUID} to {transform.position} : {rb.velocity}" + // $"\nNetwork Message was {rigidbodyUpdate.position} : {rigidbodyUpdate.velocity}"); } }
static void Postfix(VTMapManager __instance) { if (TacViewDataLogger.SceneReloaded != null) { TacViewDataLogger.SceneReloaded.Invoke(); } }
public void BulletHit(Packet packet) { bulletMessage = (Message_BulletHit)((PacketSingle)packet).message; Debug.Log("handling bullet hit"); if (bulletMessage.destUID != networkUID) { return; } RaycastHit hitInfo; Vector3 pos = VTMapManager.GlobalToWorldPoint(bulletMessage.pos); Vector3 vel = bulletMessage.dir.toVector3; Vector3 a = pos; a += vel * 100.0f; bool flag = Physics.Linecast(pos, a, out hitInfo, 1025); Hitbox hitbox = null; if (flag) { hitbox = hitInfo.collider.GetComponent <Hitbox>(); if ((bool)hitbox && (bool)hitbox.actor) { Debug.Log("found target bullet hit"); hitbox.Damage(bulletMessage.damage, hitInfo.point, Health.DamageTypes.Impact, hitbox.actor, "lol"); BulletHitManager.instance.CreateBulletHit(hitInfo.point, -vel, true); } } }
public void GroundUpdate(Packet packet) { lastMessage = (Message_ShipUpdate)((PacketSingle)packet).message; if (lastMessage.UID != networkUID) { return; } targetPositionGlobal = lastMessage.position + lastMessage.velocity.toVector3 * Networker.pingToHost; targetVelocity = lastMessage.velocity.toVector3; //targetRotation = lastMessage.rotation; //targetRotation = targetRotation.normalized; //could not get the rotation to work for whatever reason, so ground moves face their velocity vector //Debug.Log("Ground reciever rotation is: " + lastMessage.rotation.ToString()); if ((VTMapManager.GlobalToWorldPoint(lastMessage.position) - groundUnitMover.transform.position).magnitude > 100) { Debug.Log("Ground mover is too far, teleporting."); groundUnitMover.transform.position = VTMapManager.GlobalToWorldPoint(lastMessage.position); Quaternion qs = lastMessage.rotation; qs = qs.normalized; groundUnitMover.transform.rotation = qs; smoothedPosition = lastMessage.position; if (targetVelocity.sqrMagnitude > 1) { smoothedRotation = Quaternion.LookRotation(targetVelocity); } //smoothedRotation = lastMessage.rotation; //smoothedRotation = smoothedRotation.normalized; } }
public void RigidbodyUpdate(Packet packet) { Message_RigidbodyUpdate rigidbodyUpdate = (Message_RigidbodyUpdate)((PacketSingle)packet).message; //Debug.Log($"Rigidbody Update\nOur Network ID = {networkUID} Packet Network ID = {rigidbodyUpdate.networkUID}"); if (rigidbodyUpdate.networkUID != networkUID) { return; } if (rigidbodyUpdate.sequenceNumber <= mostCurrentUpdateNumber) { return; } mostCurrentUpdateNumber = rigidbodyUpdate.sequenceNumber; globalTargetPosition = rigidbodyUpdate.position + rigidbodyUpdate.velocity * latency; localTargetPosition = VTMapManager.GlobalToWorldPoint(globalTargetPosition); targetVelocity = rigidbodyUpdate.velocity.toVector3; targetRotation = rigidbodyUpdate.rotation * Quaternion.Euler(rigidbodyUpdate.angularVelocity.toVector3 * latency); targetRotationVelocity = rigidbodyUpdate.angularVelocity.toVector3; if (Vector3.Distance(transform.position, localTargetPosition) > positionThreshold) { //Debug.Log("Outside of thresh hold, moving " + gameObject.name); transform.position = localTargetPosition; transform.rotation = rigidbodyUpdate.rotation; } }
protected override void UpdateTask() { base.UpdateTask(); float maxDistance = AirTraffic.trafficRadius * 1.01f; if ((AirTraffic.instance.mpMode || AirTraffic.settings.mpTestMode) && AirTraffic.instance.akutan == false) { maxDistance = AirTraffic.mapRadius * 1.4f; } if (AirTraffic.DistanceFromOrigin(VTMapManager.WorldToGlobalPoint(transform.position)) > maxDistance) { if (aircraft.aiPilot.commandState == AIPilot.CommandStates.Orbit) { Debug.Log(gameObject.name + " went outta bounds, respawning elsewhere"); Vector3D pos = AirTraffic.PointOnCruisingRadius(); Vector3 dir = -pos.toVector3; dir.y = 0; Spawn(pos, dir); } else { if (health.normalizedHealth != 0) { Debug.Log(gameObject.name + " went outta bounds untintentionally, destroying them for our saftey"); health.Kill(); } } } }
public void BulletHit(Packet packet) { bulletMessage = (Message_BulletHit)((PacketSingle)packet).message; Debug.Log("handling bullet hit"); if (bulletMessage.destUID != networkUID) { return; } Vector3 pos = VTMapManager.GlobalToWorldPoint(bulletMessage.pos); Vector3 vel = bulletMessage.dir.toVector3; RaycastHit[] hits; hits = Physics.RaycastAll(pos, vel, 100.0f, 1025); Hitbox hitbox = null; for (int i = 0; i < hits.Length; i++) { RaycastHit hit = hits[i]; hitbox = hit.collider.GetComponent <Hitbox>(); if ((bool)hitbox && (bool)hitbox.actor) { Debug.Log("found target bullet hit"); hitbox.Damage(bulletMessage.damage, hit.point, Health.DamageTypes.Impact, hitbox.actor, "Bullet Hit Network"); BulletHitManager.instance.CreateBulletHit(hit.point, -vel, true); } } }
void FixedUpdate() { targetPositionGlobal += targetVelocity * Time.fixedDeltaTime; targetPosition = VTMapManager.GlobalToWorldPoint(new Vector3D(targetPositionGlobal)); ship.rb.MovePosition(ship.transform.position + targetVelocity * Time.fixedDeltaTime + ((targetPosition - ship.transform.position) * Time.fixedDeltaTime) / smoothTime); ship.rb.velocity = targetVelocity + (targetPosition - ship.transform.position) / smoothTime; ship.rb.MoveRotation(Quaternion.Lerp(ship.transform.rotation, targetRotation, Time.fixedDeltaTime / rotSmoothTime)); }
public static Vector3 GetTargetPos() { if (targetActor != null) { return(targetActor.transform.position); } return(VTMapManager.GlobalToWorldPoint(lastTargetPositon)); }
private void FixedUpdate() { if (thisMissile == null) { Debug.LogError("thisMissile null."); } if (hasFired != thisMissile.fired) { Debug.Log("Missile fired " + thisMissile.name); hasFired = true; RigidbodyNetworker_Sender rbSender = gameObject.AddComponent <RigidbodyNetworker_Sender>(); rbSender.networkUID = networkUID; } if (thisMissile != null && thisMissile.fired) { if (lastMessage == null) { Debug.LogError("lastMessage null"); } lastMessage.networkUID = networkUID; lastMessage.guidanceMode = thisMissile.guidanceMode; if (thisMissile.guidanceMode == Missile.GuidanceModes.Radar) { if (thisMissile.radarLock != null && thisMissile.radarLock.actor != null) { lastMessage.targetPosition = VTMapManager.WorldToGlobalPoint(thisMissile.radarLock.actor.transform.position); foreach (var AI in AIManager.AIVehicles) { if (AI.actor == thisMissile.radarLock.actor) { lastMessage.radarLock = AI.vehicleUID; // Debug.Log($"Missile {gameObject.name} has found its lock {AI.actor.name} with an uID of {AI.vehicleUID} while trying to lock {thisMissile.radarLock.actor.name}"); } } } } else if (thisMissile.guidanceMode == Missile.GuidanceModes.Optical) { lastMessage.targetPosition = VTMapManager.WorldToGlobalPoint(thisMissile.opticalTargetActor.transform.position); //lastMessage.seekerRotation = thisMissile.heatSeeker.transform.rotation; } else if (thisMissile.guidanceMode == Missile.GuidanceModes.Heat) { //lastMessage.targetPosition = VTMapManager.WorldToGlobalPoint(thisMissile.opticalTargetActor.transform.position); lastMessage.seekerRotation = thisMissile.heatSeeker.transform.rotation; } SendMessage(false); } /*if (thisMissile.guidanceMode == Missile.GuidanceModes.Radar) * { * if (thisMissile.isPitbull) * { * Debug.Log(gameObject.name + " is now pitbull."); * } * }*/ }
void FixedUpdate() { ///stops baha touching our velocities actor.fixedVelocityUpdate = true; if (rb == null) { Debug.LogError("Rigid body is null on object " + gameObject.name); } if (rb.isKinematic == false) { rb.isKinematic = true; Debug.Log("Rigidbody was not kinematic on " + gameObject.name); } if (kplane != null) // yes this can be null on objects that arent airplanes { if (kplane.enabled == true) { kplane.enabled = false; Debug.Log("Disabled kplane again on " + gameObject.name); } } if (playerWeRepresent == null) { int playerID = PlayerManager.FindPlayerIDFromNetworkUID(networkUID); //get the ping of the player we represent if (playerID == -1) { //we are not a player, get the ping from the host playerID = PlayerManager.FindPlayerIDFromNetworkUID(PlayerManager.GetPlayerUIDFromCSteamID(Networker.hostID)); //getting the host } if (playerID != -1) //couldnt find host latency, that sucks { playerWeRepresent = PlayerManager.players[playerID]; } } if (playerWeRepresent != null) { //delta time needs to be added to latency as this runs after packet has arrived for a while latency = playerWeRepresent.ping + Time.fixedDeltaTime; } globalTargetPosition += new Vector3D(targetVelocity * Time.fixedDeltaTime); localTargetPosition = VTMapManager.GlobalToWorldPoint(globalTargetPosition); Quaternion quatVel = Quaternion.Euler(targetRotationVelocity * Time.fixedDeltaTime); Quaternion currentRotation = transform.rotation; currentRotation *= quatVel; targetRotation *= quatVel; rb.velocity = targetVelocity + (localTargetPosition - transform.position) / smoothingTime; //actor.SetCustomVelocity(Vector3.Lerp(actor.velocity, targetVelocity + (localTargetPosition - transform.position) / smoothingTime, Time.fixedDeltaTime / velSmoothingTime)); actor.SetCustomVelocity(rb.velocity); rb.MovePosition(transform.position + targetVelocity * Time.fixedDeltaTime + ((localTargetPosition - transform.position) * Time.fixedDeltaTime) / smoothingTime); Quaternion quat = Quaternion.Slerp(currentRotation, targetRotation, Time.fixedDeltaTime / rotSmoothingTime); rb.MoveRotation(quat.normalized); }
void FixedUpdate() { targetPositionGlobal += targetVelocity * Time.fixedDeltaTime; targetPosition = VTMapManager.GlobalToWorldPoint(targetPositionGlobal); ship.rb.MovePosition(ship.transform.position + targetVelocity * Time.fixedDeltaTime + ((targetPosition - ship.transform.position) * Time.fixedDeltaTime) / smoothTime); ship.rb.velocity = targetVelocity + (targetPosition - ship.transform.position) / smoothTime; shipTraverse.Field("_velocity").SetValue(ship.rb.velocity);//makes the wake emit partical ship.rb.MoveRotation(Quaternion.Lerp(ship.transform.rotation, targetRotation, Time.fixedDeltaTime / rotSmoothTime)); }
public override void StartTask(TrafficAI_Base ai) { Debug.Log("Starting landing at temporary task!"); TrafficAI_Transport transportAI = (TrafficAI_Transport)ai; ai.waypoint.GetTransform().position = VTMapManager.GlobalToWorldPoint(point); transportAI.aircraft.LandAtWpt(ai.waypoint); idleTimer = UnityEngine.Random.Range(15f, 30f); base.StartTask(ai); }
public override void StartTask(TrafficAI_Base ai) { Debug.Log("Starting fly off map task!"); TrafficAI_Transport ai2 = (TrafficAI_Transport)ai; ai2.waypoint.GetTransform().position = VTMapManager.GlobalToWorldPoint(AirTraffic.PointOnMapRadius()); ai2.aircraft.SetOrbitNow(ai2.waypoint, 10000, AirTraffic.cruisingAltitudes.Random()); ai2.pilot.navSpeed = UnityEngine.Random.Range(ai2.normalSpeed, ai2.pilot.maxSpeed); base.StartTask(ai2); }
public static Vector3D GetPlayerPosition() { if ((instance.mpMode || settings.mpTestMode) && instance.akutan == false) { return(new Vector3D(mapRadius, 0, mapRadius)); } else { return(VTMapManager.WorldToGlobalPoint(FlightSceneManager.instance.playerActor.gameObject.transform.position)); } }
public override void StartTask(TrafficAI_Base ai) { Debug.Log("Starting scout airbase!"); TrafficAI_CAP capAI = (TrafficAI_CAP)ai; ai.waypoint.GetTransform().position = VTMapManager.GlobalToWorldPoint(point); capAI.Orbit(ai.waypoint, radius, alt); idleTimer = UnityEngine.Random.Range(30f, 120f); arived = false; base.StartTask(ai); }
void Update() { if (targetActor != null) { lastTargetPositon = VTMapManager.WorldToGlobalPoint(targetActor.transform.position); lastTargetVelocity = targetActor.velocity; } else { lastTargetPositon += lastTargetVelocity * Time.deltaTime; } }
public override void Spawn(Vector3D pos, Vector3 dir) { Debug.Log("Reseting aircraft"); foreach (CAP_Aircraft plane in formation) { plane.aircraft.transform.position = VTMapManager.GlobalToWorldPoint(pos); plane.aircraft.transform.LookAt(plane.aircraft.transform.position + dir); plane.rb.velocity = plane.gameObject.transform.forward * plane.pilot.navSpeed; plane.gameObject.GetComponentInChildren <GearAnimator>().RetractImmediate(); plane.gameObject.GetComponent <KinematicPlane>().SetToKinematic(); Debug.Log("aircraft reset"); } }
private void Update() { if (receivedGlobalUID && thisMissile != null && thisMissile.fired) { lastMessage.networkUID = networkUID; lastMessage.position = VTMapManager.WorldToGlobalPoint(rigidbody.position); lastMessage.rotation = new Vector3D(rigidbody.rotation.eulerAngles); if (thisMissile.radarLock != null && thisMissile.radarLock.actor != null) { lastMessage.targetPosition = VTMapManager.WorldToGlobalPoint(thisMissile.radarLock.actor.transform.position); } SendMessage(false); } }
int GetSpawnID(AICarrierSpawn carrier) { Vector3 b = VTMapManager.GlobalToWorldPoint(new Vector3D(actor.transform.position)); int result = 0; float num = float.MaxValue; for (int i = 0; i < carrier.spawnPoints.Count; i++) { float sqrMagnitude = (carrier.spawnPoints[i].spawnTf.position - b).sqrMagnitude; if (sqrMagnitude < num) { result = i; num = sqrMagnitude; } } return(result); }
private Actor GetActorAtPosition(Vector3D globalPos) { Vector3 worldPos = VTMapManager.GlobalToWorldPoint(globalPos); Actor result = null; float num = 250000f; for (int i = 0; i < TargetManager.instance.allActors.Count; i++) { float sqrMagnitude = (TargetManager.instance.allActors[i].position - worldPos).sqrMagnitude; if (sqrMagnitude < num) { num = sqrMagnitude; result = TargetManager.instance.allActors[i]; } } return(result); }
private void FixedUpdate() { globalLastPosition += new Vector3D(lastVelocity * Time.fixedDeltaTime); localLastPosition = VTMapManager.GlobalToWorldPoint(globalLastPosition); Quaternion quatVel = Quaternion.Euler(lastAngularVelocity * Time.fixedDeltaTime); lastRotation *= quatVel; lastUp = lastRotation * Vector3.up; lastForward = lastRotation * Vector3.forward; tick += Time.fixedDeltaTime; if (tick > 1.0f / tickRate || Vector3.Distance(localLastPosition, transform.TransformPoint(originOffset)) > threshold || Vector3.Angle(lastUp, transform.up) > angleThreshold || Vector3.Angle(lastForward, transform.forward) > angleThreshold) { tick = 0.0f; lastUp = transform.up; lastForward = transform.forward; globalLastPosition = VTMapManager.WorldToGlobalPoint(transform.TransformPoint(originOffset)); lastVelocity = rb.velocity; lastRotation = transform.rotation; lastAngularVelocity = rb.angularVelocity * Mathf.Rad2Deg; lastMessage.position = VTMapManager.WorldToGlobalPoint(transform.TransformPoint(originOffset)); lastMessage.rotation = transform.rotation; if (Multiplayer.SoloTesting) { lastMessage.position += new Vector3D(-30, 0, 0); } lastMessage.velocity = new Vector3D(rb.velocity); lastMessage.angularVelocity = new Vector3D(rb.angularVelocity * Mathf.Rad2Deg); lastMessage.networkUID = networkUID; lastMessage.sequenceNumber = ++updateNumber; if (Networker.isHost) { NetworkSenderThread.Instance.SendPacketAsHostToAllClients(lastMessage, Steamworks.EP2PSend.k_EP2PSendUnreliableNoDelay); } else { NetworkSenderThread.Instance.SendPacketToSpecificPlayer(Networker.hostID, lastMessage, Steamworks.EP2PSend.k_EP2PSendUnreliableNoDelay); } } // Temperz STOP KILLING PERFORMANCE AND HARD DRIVES! //Debug.Log($"{actor.name} is not outside of the threshold {Threshold}, the distance is {Vector3.Distance(lastPos, gameObject.transform.position)} not updating it."); }
public void ShipUpdate(Packet packet) { lastMessage = (Message_ShipUpdate)((PacketSingle)packet).message; if (lastMessage.UID != networkUID) { return; } targetPositionGlobal = lastMessage.position.toVector3 + lastMessage.velocity.toVector3 * Networker.pingToHost; targetVelocity = lastMessage.velocity.toVector3; targetRotation = lastMessage.rotation; if ((VTMapManager.GlobalToWorldPoint(lastMessage.position) - ship.transform.position).magnitude > 100) { Debug.Log("Ship is too far, teleporting. This message should apear once per ship at spawn, if ur seeing more something is probably fucky"); ship.transform.position = VTMapManager.GlobalToWorldPoint(lastMessage.position); } }
public void BulletHit(Packet packet) { bulletMessage = (Message_BulletHit)((PacketSingle)packet).message; Debug.Log("handling bullet hit"); if (bulletMessage.destUID != networkUID) { return; } RaycastHit hitInfo; Vector3 pos = VTMapManager.GlobalToWorldPoint(bulletMessage.pos); Vector3 vel = bulletMessage.dir.toVector3; Vector3 a = pos; a += vel * 100.0f; bool flag = Physics.Linecast(pos, a, out hitInfo, 1025); Actor source = null; if (AIDictionaries.allActors.ContainsKey(bulletMessage.sourceActorUID)) { source = AIDictionaries.allActors[bulletMessage.sourceActorUID]; } Hitbox hitbox = null; if (flag) { hitbox = hitInfo.collider.GetComponent <Hitbox>(); if ((bool)hitbox && (bool)hitbox.actor) { Debug.Log("found target bullet hit"); hitbox.Damage(bulletMessage.damage * 3.0f, hitInfo.point, Health.DamageTypes.Impact, source, "Bullet Impact"); BulletHitManager.instance.CreateBulletHit(hitInfo.point, -vel, true); } } else { health.Damage(bulletMessage.damage * 3.0f, ownerActor.gameObject.transform.position, Health.DamageTypes.Impact, source, "Bullet Impact"); BulletHitManager.instance.CreateBulletHit(ownerActor.gameObject.transform.position, -vel, true); } }
public void getHeightMap(bool customScene, string TacViewFolder, VTMapManager mm) { if (!gameHeightmap) { // This probably shouldn't be hit anymore? if (customScene) { support.WriteLog("Getting custom map"); VTMap map = support.mm.map; if (map != null) { support.WriteLog("Getting texture data"); Texture2D myTexture2D = getTexture(support.mm.fallbackHeightmap); saveHeightMap(myTexture2D, map, TacViewFolder); generateMapXML(myTexture2D, map, customScene, TacViewFolder); } else { support.WriteLog("Unable to build heightmap. Map is null!"); } } else { VTMap map = support.getMap(); support.WriteLog("Getting built in map"); Texture2D myTexture2D = getTexture(mm.fallbackHeightmap); saveHeightMap(myTexture2D, map, TacViewFolder); generateMapXML(myTexture2D, map, customScene, TacViewFolder); } } else { support.WriteLog("We already have a heightmap thank god."); VTMap map = support.mm.map; Texture2D myTexture2D = getTexture(gameHeightmap); saveHeightMap(myTexture2D, map, TacViewFolder); generateMapXML(myTexture2D, map, customScene, TacViewFolder); } }
void FixedUpdate() { if (targetVelocity.sqrMagnitude > 1) { targetRotation = Quaternion.LookRotation(targetVelocity); } targetPositionGlobal += targetVelocity * Time.fixedDeltaTime; smoothedPosition = smoothedPosition + targetVelocity * Time.fixedDeltaTime + ((targetPositionGlobal - smoothedPosition) * Time.fixedDeltaTime) / smoothTime; smoothedRotation = Quaternion.Slerp(smoothedRotation, targetRotation, Time.fixedDeltaTime / rotSmoothTime); smoothedRotation = smoothedRotation.normalized; Vector3 adjustedPos = VTMapManager.GlobalToWorldPoint(smoothedPosition); Vector3 surfaceNormal = smoothedRotation * Vector3.up; Vector3 surfaceRight = smoothedRotation * Vector3.right; Vector3 surfaceForward = smoothedRotation * Vector3.forward; Quaternion adjustedRotation = smoothedRotation; RaycastHit hit; if (Physics.Raycast(adjustedPos + 500 * Vector3.up, Vector3.down, out hit, 1000, 1, QueryTriggerInteraction.Ignore)) { adjustedPos = hit.point + hit.normal * groundUnitMover.height; surfaceNormal = hit.normal; surfaceRight = Vector3.Cross(surfaceNormal, smoothedRotation * Vector3.forward); surfaceForward = Vector3.Cross(surfaceRight, surfaceNormal); if (surfaceForward != Vector3.zero && surfaceNormal != Vector3.zero) { adjustedRotation = Quaternion.LookRotation(surfaceForward, surfaceNormal); } } adjustedRotation = adjustedRotation.normalized; //groundTraverse.Field("velocity").SetValue(targetVelocity + (targetPositionGlobal - smoothedPosition).toVector3 / smoothTime); rb.MovePosition(adjustedPos); rb.MoveRotation(adjustedRotation);//move rotation was throwing "Rotation quaternions must be unit length" if (isSoldier) { soldier.animator.SetFloat(walkingAnimation, (targetVelocity + (targetPositionGlobal - smoothedPosition).toVector3 / smoothTime).magnitude); } }
private void LateUpdate() { lastMessage.position = VTMapManager.WorldToGlobalPoint(transform.position); lastMessage.rotation = new Vector3D(transform.rotation.eulerAngles); if (Multiplayer.SoloTesting) { lastMessage.position += new Vector3D(-30, 0, 0); } lastMessage.velocity = new Vector3D(rb.velocity); lastMessage.angularVelocity = new Vector3D(rb.angularVelocity); lastMessage.networkUID = networkUID; if (Networker.isHost) { Networker.SendGlobalP2P(lastMessage, Steamworks.EP2PSend.k_EP2PSendUnreliableNoDelay); } else { Networker.SendP2P(Networker.hostID, lastMessage, Steamworks.EP2PSend.k_EP2PSendUnreliableNoDelay); } }
private void FixedUpdate() { globalLastPosition += new Vector3D(lastVelocity * Time.fixedDeltaTime); localLastPosition = VTMapManager.GlobalToWorldPoint(globalLastPosition); Quaternion quatVel = Quaternion.Euler(lastAngularVelocity * Time.fixedDeltaTime); lastRotation *= quatVel; lastUp = lastRotation * Vector3.up; lastForward = lastRotation * Vector3.forward; tick += Time.fixedDeltaTime; if (tick > 1.0f / tickRate || Vector3.Distance(localLastPosition, transform.TransformPoint(originOffset)) > threshold || Vector3.Angle(lastUp, transform.up) > angleThreshold || Vector3.Angle(lastForward, transform.forward) > angleThreshold) { tick = 0.0f; lastUp = transform.up; lastForward = transform.forward; globalLastPosition = VTMapManager.WorldToGlobalPoint(transform.TransformPoint(originOffset)); lastVelocity = rb.velocity; lastRotation = transform.rotation; lastAngularVelocity = rb.angularVelocity * Mathf.Rad2Deg; lastMessage.position = VTMapManager.WorldToGlobalPoint(transform.TransformPoint(originOffset)); lastMessage.rotation = transform.rotation; lastMessage.velocity = new Vector3D(rb.velocity); lastMessage.angularVelocity = new Vector3D(rb.angularVelocity * Mathf.Rad2Deg); lastMessage.networkUID = networkUID; lastMessage.sequenceNumber = ++updateNumber; if (Networker.isHost) { Networker.addToUnreliableSendBuffer(lastMessage); } else { NetworkSenderThread.Instance.SendPacketToSpecificPlayer(Networker.hostID, lastMessage, Steamworks.EP2PSend.k_EP2PSendUnreliable); } } }
void FixedUpdate() { timer += Time.fixedDeltaTime; if (timer > 1) { timer = 0; lastMessage.position = VTMapManager.WorldToGlobalPoint(ship.transform.position); lastMessage.rotation = ship.transform.rotation; lastMessage.velocity = new Vector3D(ship.velocity); lastMessage.UID = networkUID; if (Networker.isHost) { NetworkSenderThread.Instance.SendPacketAsHostToAllClients(lastMessage, Steamworks.EP2PSend.k_EP2PSendUnreliableNoDelay); } else { NetworkSenderThread.Instance.SendPacketToSpecificPlayer(Networker.hostID, lastMessage, Steamworks.EP2PSend.k_EP2PSendUnreliableNoDelay); } } }
static bool Prefix(GPSTargetSystem __instance, Vector3 worldPosition, string prefix) { Vector3 pos = worldPosition; string msgp = prefix; Debug.Log("sending GPS"); Message_GPSData gpsm = new Message_GPSData(PlayerManager.localUID, VTMapManager.WorldToGlobalPoint(pos), "MP", PlayerManager.teamLeftie, __instance.currentGroup.groupName); if (PlayerManager.sendGPS) { if (Networker.isHost) { NetworkSenderThread.Instance.SendPacketAsHostToAllClients(gpsm, Steamworks.EP2PSend.k_EP2PSendReliable); } else { NetworkSenderThread.Instance.SendPacketToSpecificPlayer(Networker.hostID, gpsm, Steamworks.EP2PSend.k_EP2PSendReliable); } } return(true); }