public override void Init() { //if (CameraManName != null) CameraMan = CameraManName; if (!ObjectPrivate.TryGetFirstComponent(out RigidBody)) { Log.Write(LogLevel.Error, __SimpleTag, "Simple Mover requires a Rigidbody set to motion type Keyframed"); return; } if (RigidBody.GetMotionType() != RigidBodyMotionType.MotionTypeKeyframed) { Log.Write(LogLevel.Error, __SimpleTag, "Simple Mover requires a Rigidbody set to motion type Keyframed"); return; } SubscribeToAll("SetCameraMan", InitializeCameraMan); SubscribeToAll("SetDirector", InitializeDirector); if (EnableEvent != "") { Log.Write("Enable Event was not null: " + EnableEvent); SubscribeToAll(EnableEvent, ReadInParameters); } else { ReadInParameters(null); //executes it by passing null data } if (DisableEvent != "") { SubscribeToAll(DisableEvent, Unsubscribe); } }
bool ResetToInitialPosition(RigidBodyComponent rigidBody) { ObjectPrivate objectPrivate = ScenePrivate.FindObject(rigidBody.ComponentId.ObjectId); if (objectPrivate != null && objectPrivate.IsValid) { try { var motionType = rigidBody.GetMotionType(); WaitFor(rigidBody.SetMotionType, RigidBodyMotionType.MotionTypeKeyframed); rigidBody.SetAngularVelocity(Vector.Zero); rigidBody.SetLinearVelocity(Vector.Zero); rigidBody.SetOrientation(objectPrivate.InitialRotation); rigidBody.SetPosition(objectPrivate.InitialPosition); rigidBody.SetMotionType(motionType); return(true); } catch { Log.Write(LogLevel.Error, __SimpleTag, "Position Reset: error resetting object position."); } } return(false); }
protected override void SimpleInit() { if (!ObjectPrivate.TryGetFirstComponent <RigidBodyComponent>(out RigidBody) || RigidBody.GetMotionType() == RigidBodyMotionType.MotionTypeStatic) { Log.Write(LogLevel.Error, __SimpleTag, "SimpleReset requires a non-static rigid body to work properly."); return; } if (StartEnabled) { Subscribe(null); } SubscribeToAll(EnableEvent, Subscribe); SubscribeToAll(DisableEvent, Unsubscribe); }
// Logic! public override void Init() { if (!ObjectPrivate.TryGetFirstComponent(out _rb)) { Log.Write(LogLevel.Error, "ImpulseBump can't find a RigidBodyComponent!"); return; } if (_rb.GetMotionType() != RigidBodyMotionType.MotionTypeDynamic) { Log.Write(LogLevel.Error, "ImpulseBump only works on dynamic objects! Set the motion type to 'Dynamic' and try again."); return; } // Check the input parameters to determine what behaviors will be in use _applyLinearImpulse = (LinearImpulseDirection.LengthSquared() > 0.0f); _applyAngularImpulse = (AngularVariance.LengthSquared() > 0.0f); // Don't trust users to give us a normalized direction vector! if (_applyLinearImpulse) { LinearImpulseDirection = LinearImpulseDirection.Normalized(); } // Apply the impulse force when the object is clicked, if it has been configured to use this mode if (InteractionImpulse) { ObjectPrivate.AddInteractionData addData = (ObjectPrivate.AddInteractionData)WaitFor(ObjectPrivate.AddInteraction, "", true); addData.Interaction.Subscribe((InteractionData data) => { ApplyImpulse(); }); } // Apply the impulse force when a script event is received, if one has been specified if (!string.IsNullOrWhiteSpace(ImpulseScriptEvent)) { SubscribeToScriptEvent(ImpulseScriptEvent, (ScriptEventData data) => { // Force anyone holding the object to drop it _rb.ReleaseHeldObject(); ApplyImpulse(); }); } }
public override void Init() { if (ObjectPrivate.TryGetFirstComponent(out _rb)) { _rb.SetCanGrab(false); // Disable grabbing for this object if (_rb.GetMotionType() == RigidBodyMotionType.MotionTypeDynamic) { MyInteraction.Subscribe((InteractionData data) => { _rb.AddLinearImpulse(Vector.Up * 100.0f); }); } else { Log.Write(LogLevel.Warning, "RigidBodyImpulseScript not running on a dynamic object!"); } } else { Log.Write(LogLevel.Warning, "RigidBodyImpulseScript not running on an object with a physics volume!"); } }
protected override void SimpleInit() { if (!ObjectPrivate.TryGetFirstComponent(out RigidBody)) { Log.Write(LogLevel.Error, __SimpleTag, "Simple Mover requires a Rigidbody set to motion type Keyframed"); return; } if (RigidBody.GetMotionType() != RigidBodyMotionType.MotionTypeKeyframed) { Log.Write(LogLevel.Error, __SimpleTag, "Simple Mover requires a Rigidbody set to motion type Keyframed"); return; } thisObjectData = new SimpleData(this); thisObjectData.SourceObjectId = ObjectPrivate.ObjectId; thisObjectData.AgentInfo = null; thisObjectData.ObjectId = ObjectPrivate.ObjectId; RigidBody.SetCenterOfMass(RotationPivot); Subscribe(null); Quaternion rotation = Quaternion.FromEulerAngles(Mathf.RadiansPerDegree * RotationOffset); returnRotation = ObjectPrivate.InitialRotation; movedRotation = returnRotation * rotation; numTurns = (int)((RotationOffset.Length() + 179.0f) / 360f); bool noRotation = RotationOffset.Length() < 0.5f; if (noRotation) { worldRotationAxis = Vector.Up; } else { float rotationAngle; rotation.ToAngleAxis(out rotationAngle, out localRotationAxis); if (Math.Abs(rotationAngle % TwoPI) < 0.001f) { // rotation axis won't be calculated correctly for exact multiple of 360 rotation // adjust euler angles slightly and re-calculate float x = RotationOffset.X; float y = RotationOffset.Y; float z = RotationOffset.Z; if (x != 0) { x = Math.Sign(x) * (Math.Abs(x) - 1.0f); } if (y != 0) { y = Math.Sign(y) * (Math.Abs(y) - 1.0f); } if (z != 0) { z = Math.Sign(z) * (Math.Abs(z) - 1.0f); } Vector adjustedOffset = new Vector(x, y, z); Quaternion adjustedRotation = Quaternion.FromEulerAngles(Mathf.RadiansPerDegree * adjustedOffset); float tempAngle; adjustedRotation.ToAngleAxis(out tempAngle, out localRotationAxis); } worldRotationAxis = localRotationAxis.Rotate(ref returnRotation); } float moveAngle = GetAngleFromZero(movedRotation); rotateSpeed = Math.Abs(moveAngle + numTurns * TwoPI) / (MoveDuration * SpeedCurveAverage()); if (!noRotation) { Quaternion unitRotation = Quaternion.FromAngleAxis(1f, localRotationAxis); turnDirection = Math.Sign(GetAngleFromZero(returnRotation * unitRotation)); } returnPosition = ObjectPrivate.InitialPosition + RotationPivot.Rotate(ref returnRotation); movedPosition = returnPosition + (PositionOffset).Rotate(ref returnRotation); translateSpeed = (movedPosition - returnPosition).Length() / (MoveDuration * SpeedCurveAverage()); if (StartMoved) { RigidBody.SetOrientation(movedRotation, (e) => { SetPositionOfCOM(movedPosition); }); turnCount = numTurns; state = State.Moved; } else { SetPositionOfCOM(returnPosition); state = State.Returned; } if (__SimpleDebugging) { Log.Write("rotation angle:" + moveAngle + " around:" + localRotationAxis + " world space axis:" + worldRotationAxis + " revolutions:" + numTurns); } }