private void Deploy() { if (deployed) { return; } OnMoving.Fire(0f, 1f); if (UIPartActionController.Instance is UIPartActionController partActionController && partActionController.GetItem(part, false) is UIPartActionWindow window) { window.displayDirty = true; } foreach (FairingSlice slice in slices) { GameObject gameObject = slice.SliceRootObject; physicalObject physObj = physicalObject.ConvertToPhysicalObject(part, gameObject); Rigidbody rigidBody = physObj.rb; rigidBody.useGravity = true; rigidBody.mass = slice.Mass; rigidBody.centerOfMass = slice.CalculateCoM(); rigidBody.drag = part.Rigidbody.drag / numSlices; rigidBody.angularDrag = part.Rigidbody.angularDrag; rigidBody.angularVelocity = part.Rigidbody.angularVelocity; rigidBody.maxAngularVelocity = PhysicsGlobals.MaxAngularVelocity; rigidBody.velocity = part.Rigidbody.velocity + Vector3.Cross(part.Rigidbody.worldCenterOfMass - vessel.CurrentCoM, vessel.angularVelocity); Vector3 planeNormal = part.partTransform.TransformDirection(axis); Vector3 centerOfMassDirection = (rigidBody.worldCenterOfMass - part.Rigidbody.worldCenterOfMass).normalized; Vector3 outDirection = Vector3.ProjectOnPlane(centerOfMassDirection, planeNormal).normalized; Vector3 forceDirection = (planeNormal * 0.5f + outDirection).normalized; Vector3 torqueDirection = Vector3.Cross(planeNormal, outDirection); rigidBody.AddForce(forceDirection * deploySpeed, ForceMode.VelocityChange); rigidBody.AddTorque(torqueDirection * deployAngularSpeed, ForceMode.VelocityChange); } slices.Clear(); part.ModifyCoM(); needsNotifyFARToRevoxelize = true; NotifyFARToRevoxelize(); part.DragCubes.SetCubeWeight(DRAG_CUBE_NAME_CLOSED, 0); part.DragCubes.SetCubeWeight(DRAG_CUBE_NAME_DEPLOYED, 1); part.DragCubes.ForceUpdate(weights: true, occlusion: true); OnStop.Fire(1f); HideDeployEvent(); deployed = true; GameEvents.onVesselWasModified.Fire(vessel); }
private void OnVesselWasModified(Vessel v) { bool wasDecoupled = decoupled; CheckDecoupled(); if (!wasDecoupled && decoupled) { OnMoving.Fire(0, 1); OnStop.Fire(1); } }
public new void Decouple() { if (waitForAnimation && (object)anim != null) { anim.Play(animationName); isDecoupling = true; OnMoving.Fire(0f, 1f); StartCoroutine(DelayedDecouple()); } else { OnDecouple(); } }
private void OnVesselWasModified(Vessel v) { if ((object)v != null && v == vessel) { if (!(isDecoupling || isDecoupled)) { if ((object)part.FindAttachNode(this.explosiveNodeID).attachedPart == null) { isDecoupling = true; OnMoving.Fire(0f, 1f); OnStop.Fire(1f); } } } }
public void Decouple() { OnMoving.Fire(0, 1); if (decoupler != null && !decoupler.isDecoupled) { decoupler.Decouple(); } foreach (ModuleDecouple d in panels) { if (!d.isDecoupled) { d.Decouple(); } } OnStop.Fire(1); }
private void OnEditorToggleJettisoned(BaseField field, object oldValue) { if (!HighLogic.LoadedSceneIsEditor) { return; } OnMoving.Fire(isJettisoned ? 0 : 1, isJettisoned ? 1 : 0); if (jettisons.Length > 0) { SetJettisoned(isJettisoned); } OnStop.Fire(isJettisoned ? 1 : 0); }
// TODO Consider deprecating checkForDecoupling; it should no longer be necessary private void checkForDecoupling(EventReport separationData) { if (separationData.eventType == FlightEvents.STAGESEPARATION && separationData.origin == this.part) { // PROBABLY got called because we decoupled, but no way to know because ModuleAnchoredDecoupler doesn't SET isDecoupled until after the event fires. OnMoving.Fire(0f, 1f); if (animationName != "" && (object)anim != null && (!this.animationComplete || !this.anim.IsPlaying(animationName))) { this.anim.Play(animationName); this.animationComplete = true; Debug.Log("ModuleAnimatedAnchoredDecoupler.onStageSeparation() triggered animation " + this.animationName); } this.isDecoupling = true; this.OnStop.Fire(1f); } }
public void Jettison() { if (isJettisoned) { return; } if (jettisons.Length == 0) { return; } OnMoving.Fire(0, 1); for (int i = 0; i < jettisons.Length; i++) { Rigidbody rb = physicalObject.ConvertToPhysicalObject(part, jettisons[i].gameObject).rb; rb.useGravity = true; rb.mass = jettisonedObjectMass / jettisons.Length; rb.maxAngularVelocity = PhysicsGlobals.MaxAngularVelocity; rb.angularVelocity = part.Rigidbody.angularVelocity; rb.velocity = part.Rigidbody.velocity + Vector3.Cross(part.Rigidbody.worldCenterOfMass - vessel.CurrentCoM, vessel.angularVelocity); Vector3 d = jettisonDirection; if (d == Vector3.zero) { d = Vector3.Normalize(rb.transform.position - part.transform.position); } else { d = part.transform.TransformDirection(d); } //rb.AddForce(part.transform.TransformDirection(jettisonDirection) * (jettisonForce * 0.5f), ForceMode.Force); rb.AddForceAtPosition(d * (jettisonForce * 0.5f), part.transform.position, ForceMode.Force); rb.AddTorque(d * jettisonTorque, ForceMode.VelocityChange); //part.Rigidbody.AddForce(d * (-jettisonForce * 0.5f), ForceMode.Force); } jettisons = new Transform[0]; isJettisoned = true; SetJettisoned(isJettisoned); OnStop.Fire(1); }
private void OnVesselWasModified(Vessel v) { if ((object)v != null && v == vessel) { if (!(isDecoupling || isDecoupled)) { Part p; p = this.ExplosiveNode.attachedPart; if (p = null) { isDecoupling = true; OnMoving.Fire(0f, 1f); OnStop.Fire(1f); } } } }
public void SetDeployed(bool newState) { if (deployed != newState) { if (newState) { OnMoving.Fire(stowedAnchor, deployedAnchor); } else { OnMoving.Fire(deployedAnchor, stowedAnchor); } OnStop.Fire(SpringAnchor()); } deployed = newState; Events["Deploy"].guiActive = !deployed; Actions["DeployAction"].active = !deployed; }
public void PlayAnimation(float speed) { float moveTo = animPosition; if (speed < 0) { moveTo = 0f; } else if (speed > 0) { moveTo = 1f; } OnMoving.Fire(animPosition, moveTo); foreach (var anim in animationStates) { anim.speed = speed; } playing = speed != 0f; }
private void fireEvents(AnimState newState) { switch (newState) { case AnimState.STOPPED_START: OnStop.Fire(0f); break; case AnimState.STOPPED_END: OnStop.Fire(1f); break; case AnimState.PLAYING_FORWARD: OnMoving.Fire(0, 1); break; case AnimState.PLAYING_BACKWARD: OnMoving.Fire(1, 0); break; default: break; } }
public override void OnActive() { if (staged) { if ((object)anim != null) { anim.Play(animationName); isDecoupling = true; OnMoving.Fire(0f, 1f); if (waitForAnimation) { StartCoroutine(DelayedDecouple()); } else { OnDecouple(); } } else { OnDecouple(); } } }
public void Jettison() { if (isJettisoned) { return; } if (jettisons.Length == 0) { return; } OnMoving.Fire(0, 1); for (int i = 0; i < jettisons.Length; i++) { Rigidbody rb = physicalObject.ConvertToPhysicalObject(part, jettisons[i].gameObject).rb; rb.useGravity = true; rb.mass = jettisonedObjectMass / jettisons.Length; rb.maxAngularVelocity = PhysicsGlobals.MaxAngularVelocity; rb.angularVelocity = part.Rigidbody.angularVelocity; rb.velocity = part.Rigidbody.velocity + Vector3.Cross(part.Rigidbody.worldCenterOfMass - vessel.CurrentCoM, vessel.angularVelocity); Vector3 d = jettisonDirection; if (d == Vector3.zero) { d = Vector3.Normalize(rb.transform.position - part.transform.position); } else { d = part.transform.TransformDirection(d); } //rb.AddForce(part.transform.TransformDirection(jettisonDirection) * (jettisonForce * 0.5f), ForceMode.Force); rb.AddForceAtPosition(d * (jettisonForce * 0.5f), part.transform.position, ForceMode.Force); part.Rigidbody.AddForce(d * (-jettisonForce * 0.5f), ForceMode.Force); } jettisons = new Transform[0]; if (part.temperature < part.skinMaxTemp) { part.skinTemperature = part.temperature; } isJettisoned = true; SetJettisoned(isJettisoned); OnStop.Fire(1); EnableOtherModules(); FXGroup effect = part.findFxGroup(fxGroupName); if (effect != null) { effect.Burst(); } GameEvents.onVesselWasModified.Fire(vessel); }
private void DoStartAnimation(float pos, float moveto) { OnMoving.Fire(animPosition, moveto); part.Effect("deploy"); }