public void MissileUpdate(Packet packet) { lastMessage = ((PacketSingle)packet).message as Message_MissileUpdate; if (lastMessage.networkUID != networkUID) { return; } if (!thisMissile.fired) { RadarLockData lockData = new RadarLockData(); lockData.actor = GetActorAtPosition(lastMessage.targetPosition); lockData.locked = true; lockData.lockingRadar = GetComponentInChildren <LockingRadar>(); //Unsure if these are on a child or not lockData.radarSymbol = GetComponentInChildren <Radar>().radarSymbol; //I'm just guessing they are thisMissile.SetRadarLock(lockData); thisMissile.Fire(); } if (lastMessage.hasMissed) { thisMissile.Detonate(); return; } rigidbody.velocity = lastMessage.velocity.toVector3; rigidbody.rotation = Quaternion.Euler(lastMessage.rotation.toVector3); if (Vector3.Distance(rigidbody.position, lastMessage.position.toVector3) > positionThreshold) { Debug.LogWarning($"Missile ({gameObject.name}) is outside the threshold. Teleporting to position."); rigidbody.position = lastMessage.position.toVector3; } }
public override void Run() { Vector3 directionToTarget = Missile.GetDirectionToTarget().normalized; Missile.transform.Translate(directionToTarget * speed * Time.deltaTime); if (Missile.GetDirectionToTarget().sqrMagnitude <= Missile.GetDetonationRadius() * Missile.GetDetonationRadius() * 0.5f) { Missile.Detonate(); } }
public void MissileUpdate(Packet packet) { lastMessage = ((PacketSingle)packet).message as Message_MissileUpdate; if (lastMessage.networkUID != networkUID) { return; } if (!thisMissile.gameObject.activeSelf) { Debug.LogError(thisMissile.gameObject.name + " isn't active in hiearchy, changing it to active."); thisMissile.gameObject.SetActive(true); } if (traverse == null) { traverse = Traverse.Create(thisML); } if (!thisMissile.fired) { Debug.Log(thisMissile.gameObject.name + " missile fired on one end but not another, firing here."); if (thisML == null) { Debug.LogError($"Missile launcher is null on missile {thisMissile.actor.name}, someone forgot to assign it."); } if (lastMessage.guidanceMode == Missile.GuidanceModes.Radar) { // thisMissile.debugMissile = true; RadarMissileLauncher radarLauncher = thisML as RadarMissileLauncher; if (!VTOLVR_Multiplayer.AIDictionaries.allActors.TryGetValue(lastMessage.radarLock, out Actor actor)) { Debug.LogWarning($"Could not resolve missile launcher radar lock from uID {lastMessage.radarLock}."); } else { if (radarLauncher.lockingRadar != null) { radarLauncher.lockingRadar.ForceLock(actor, out lockData); } else { Debug.LogWarning("Locking Radar null on object " + thisMissile.name); } } if (radarLauncher != null) { Debug.Log("Guidance mode radar, firing it as a radar missile."); traverse.Field("missileIdx").SetValue(idx); if (!radarLauncher.TryFireMissile()) { Debug.LogError($"Could not fire radar missile, lock data is as follows: Locked: {lockData.locked}, Actor: {lockData.actor}"); } else { RigidbodyNetworker_Receiver rbReceiver = gameObject.AddComponent <RigidbodyNetworker_Receiver>(); rbReceiver.networkUID = networkUID; } } } else { if (lastMessage.guidanceMode == Missile.GuidanceModes.Heat) { Debug.Log("Guidance mode Heat."); thisMissile.heatSeeker.transform.rotation = lastMessage.seekerRotation; thisMissile.heatSeeker.SetHardLock(); } if (lastMessage.guidanceMode == Missile.GuidanceModes.Optical) { Debug.Log("Guidance mode Optical."); GameObject emptyGO = new GameObject(); Transform newTransform = emptyGO.transform; newTransform.position = VTMapManager.GlobalToWorldPoint(lastMessage.targetPosition); thisMissile.SetOpticalTarget(newTransform); //thisMissile.heatSeeker.SetHardLock(); if (thisMissile.opticalLOAL) { thisMissile.SetLOALInitialTarget(VTMapManager.GlobalToWorldPoint(lastMessage.targetPosition)); } } Debug.Log("Try fire missile clientside"); traverse.Field("missileIdx").SetValue(idx); thisML.FireMissile(); RigidbodyNetworker_Receiver rbReceiver = gameObject.AddComponent <RigidbodyNetworker_Receiver>(); rbReceiver.networkUID = networkUID; } if (hasFired != thisMissile.fired) { Debug.Log("Missile fired " + thisMissile.name); hasFired = true; if (colliderLayers.Count > 0) { StartCoroutine(colliderTimer()); } } } //explode missle after it has done its RB physics fixed timestep if (lastMessage.hasExploded) { Debug.Log("Missile exploded."); if (thisMissile != null) { traverse.Field("detonated").SetValue(false); ///thisMissile.rb.velocity = thisMissile.transform.forward * 10.0f; thisMissile.Detonate(); } } }