void FixedUpdate() { //Debug stuff if (debug_disassembleConnectedParts) { debug_disassembleConnectedParts = false; PhysPart[] connectedParts = PartConnection.GetConnectedParts(originPart, true); List <PartConnection> connections = new List <PartConnection>(); foreach (PhysPart p in connectedParts) { foreach (PartConnection c in p.connections) { connections.Add(c); } } foreach (PartConnection c in connections) { c.fromPart.DisconnectPart(c.toPart); } } //Logic if (fixedCounter % 49 == 0) //once a second { //Auto-destroy if we are OOB if (Mathf.Abs(transform.position.x) > GameplayManager.instance.LevelBounds.x || Mathf.Abs(transform.position.y) > GameplayManager.instance.LevelBounds.y || Mathf.Abs(transform.position.z) > GameplayManager.instance.LevelBounds.z) { AutoDestruct(2.5f / Parts.Count); } } fixedCounter = (int)Mathf.Repeat(fixedCounter + 1, 50); }
public void MakeAllDisconnectedPartsGhosty() { if (currCraft == null) { return; } //update structure currCraft.UpdatePhysParts(true); List <PhysPart> connectedParts = new List <PhysPart>(PartConnection.GetConnectedParts(currCraft.originPart)); foreach (PhysPart part in currCraft.Parts) { if (connectedParts.Contains(part)) { if (currPart == null || PartConnection.IsConnectedToPartIgnoringInvalidParts(part, currCraft.originPart, new PhysPart[1] { currPart })) //Check if part is connected to origin, IGNORING held part. { MakePartGhosty(part, false); } } else { MakePartGhosty(part, true); } } }
public void UpdateTransformStructureIfDisconnected() { MultipartPhysBody oldParent = GetBody(); if (!CheckConnectedToOrigin()) { PhysPart[] ConnectedParts = PartConnection.GetConnectedParts(this); Transform newDebrisCraft = new GameObject(oldParent.name + " debris").transform; newDebrisCraft.SetParent(GameplayManager.GameplayTransform); Transform newParent = new GameObject("Body").transform; newParent.SetParent(newDebrisCraft); newParent.transform.position = newDebrisCraft.transform.position = transform.position; newParent.transform.rotation = newDebrisCraft.transform.rotation = transform.rotation; foreach (PhysPart p in ConnectedParts) { p.transform.SetParent(newParent); } newDebrisCraft.gameObject.AddComponent <Rigidbody>().velocity = oldParent.rb.GetPointVelocity(transform.TransformPoint(CoMoffset)); newDebrisCraft.gameObject.AddComponent <MultipartPhysBody>(); oldParent.FullRecalcPhysics(); foreach (PhysPart p in ConnectedParts) { foreach (PartComponent c in p.components) { c.OnBodyChanged(); } } } }