bool Reset(RigidBodyComponent rigidBody)
        {
            if (!rigidBody.IsValid)
            {
                Log.Write(LogLevel.Warning, __SimpleTag, "Position Reset: object is no longer in the scene, removing from reset script.");
                return(false);
            }

            if (rigidBody.GetHeldObjectInfo().IsHeld)
            {
                // Check now that the object is still in the scene.
                if (null == ScenePrivate.FindObject(rigidBody.ComponentId.ObjectId))
                {
                    return(false);
                }

                if (ForceDrop)
                {
                    rigidBody.ReleaseHeldObject((d) => { ResetToInitialPosition(rigidBody); });
                }
                else
                {
                    rigidBody.SubscribeToHeldObject(HeldObjectEventType.Release, (d) => { ResetToInitialPosition(rigidBody); }, false);
                }
                return(true);
            }
            else
            {
                return(ResetToInitialPosition(rigidBody));
            }
        }
Exemple #2
0
    // 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();
            });
        }
    }