Browse Source

Triggers + small changes

Eideren 1 year ago
parent
commit
3e0f79ce1a
3 changed files with 28 additions and 56 deletions
  1. 1 1
      en/manual/physics/colliders.md
  2. 0 3
      en/manual/physics/configuration.md
  3. 27 52
      en/manual/physics/triggers.md

+ 1 - 1
en/manual/physics/colliders.md

@@ -56,7 +56,7 @@ The contact event handler is a class that receives collision data whenever the o
 
 
 It is most often used to transform physics object into 'trigger boxes', areas that run events whenever objects, like the player character, passes through them. See [Triggers](triggers.md).
 It is most often used to transform physics object into 'trigger boxes', areas that run events whenever objects, like the player character, passes through them. See [Triggers](triggers.md).
 
 
-If the contact event handler you bind to an object is set to `NoContactResponse`, the object will never collide with anything, it will only collect collision events.
+If the contact event handler you bind to an object is set to `NoContactResponse`, the object will never prevent anything from passing through it, it will only collect collision events.
 
 
 ## See also
 ## See also
 
 

+ 0 - 3
en/manual/physics/configuration.md

@@ -3,9 +3,6 @@
 <span class="badge text-bg-primary">Beginner</span>
 <span class="badge text-bg-primary">Beginner</span>
 <span class="badge text-bg-success">Designer</span>
 <span class="badge text-bg-success">Designer</span>
 
 
-> [!WARNING]
-> This is a WIP documentation. This page is mostly done.
-
 ## Adding Bepu physics to your game
 ## Adding Bepu physics to your game
 
 
 Some projects may not come with Bepu Physics pre-installed, to add it to your project right-click on the **game** project and select `Add dependency...`
 Some projects may not come with Bepu Physics pre-installed, to add it to your project right-click on the **game** project and select `Add dependency...`

+ 27 - 52
en/manual/physics/triggers.md

@@ -3,66 +3,42 @@
 <span class="badge text-bg-primary">Beginner</span>
 <span class="badge text-bg-primary">Beginner</span>
 <span class="badge text-bg-success">Designer</span>
 <span class="badge text-bg-success">Designer</span>
 
 
-> [!WARNING]
-TODO
+A trigger is a collision shape which detects when colliders enter it, it can be used to run an event when a player character enters a room for example.
+ 
+Triggers in Stride's Bepu implementation fall into what is known as a special kind of Contact Event Handler.
 
 
-If you set a collider to be a **trigger**, other colliders no longer bump into it. Instead, they pass through.
+The contact event handler is a class that receives collision data whenever the object it is associated with collides with the world.
 
 
-The trigger detects when colliders enter it, which you can use to script events. For example, you can detect when a player character enters a room, and use this in your script to trigger an event. For more information, see [Events](../scripts/events.md).
-
->[!Note]
->[Character colliders](characters.md) can't be used as triggers.
-
-## Create a trigger 
-
-1. Create a [collider](colliders.md).
-
-2. In the **Property Grid**, under the collider component properties, select **Is Trigger**.
-
-![Select 'Is trigger'](media/triggers-select-is-trigger-checkbox.png)
-
-## Detect trigger collisions
-
-You can see when something enters the trigger using the following code:
+If the contact event handler you bind to an object is set to `NoContactResponse`, it is a Trigger, the object will never prevent anything from passing through it, it will only receive collision events.
 
 
+Here's a basic example of a component which acts as a trigger to display a message in the console:
 ```cs
 ```cs
-// Wait for an entity to collide with the trigger
-var firstCollision = await trigger.NewCollision();
-
-var otherCollider = trigger == firstCollision.ColliderA
-    ? firstCollision.ColliderB
-    : firstCollision.ColliderA;
-```
+using Stride.BepuPhysics;
+using Stride.BepuPhysics.Definitions.Contacts;
+using Stride.Engine;
 
 
-Alternatively, directly access the `TrackingHashSet`:
-
-```cs
-var trigger = Entity.Get<PhysicsComponent>();
-foreach (var collision in trigger.Collisions)
+public class Test : StartupScript, IContactEventHandler
 {
 {
-    //do something with the collision
-}
-```
-
-Or use the `TrackingHashSet` events:
+    public bool NoContactResponse => true;
 
 
-```cs
-var trigger = Entity.Get<PhysicsComponent>();
-trigger.Collisions.CollectionChanged += (sender, args) =>
-{
-    if (args.Action == NotifyCollectionChangedAction.Add)
+    void IContactEventHandler.OnStartedTouching<TManifold>(CollidableComponent eventSource, CollidableComponent other,
+        ref TManifold contactManifold,
+        bool flippedManifold,
+        int workerIndex,
+        BepuSimulation bepuSimulation)
     {
     {
-        //new collision
-        var collision = (Collision) args.Item;
-        //do something
+        Log.Warning("Entered!");
     }
     }
-    else if (args.Action == NotifyCollectionChangedAction.Remove)
+
+    void IContactEventHandler.OnStoppedTouching<TManifold>(CollidableComponent eventSource, CollidableComponent other,
+        ref TManifold contactManifold,
+        bool flippedManifold,
+        int workerIndex,
+        BepuSimulation bepuSimulation)
     {
     {
-        //old collision
-        var collision = (Collision)args.Item;
-        //do something
+        Log.Warning("Exited!");
     }
     }
-};
+}
 ```
 ```
 
 
 For an example of how to use triggers, see the [Script a trigger](script-a-trigger.md) tutorial.
 For an example of how to use triggers, see the [Script a trigger](script-a-trigger.md) tutorial.
@@ -70,6 +46,5 @@ For an example of how to use triggers, see the [Script a trigger](script-a-trigg
 ## See also
 ## See also
 
 
 * [Tutorial: Script a trigger](script-a-trigger.md)
 * [Tutorial: Script a trigger](script-a-trigger.md)
-* [Colliders](colliders.md)
-* [Collider shapes](collider-shapes.md)
-* [Events](../scripts/events.md)
+* [Collidables](colliders.md)
+* [Collider shapes](collider-shapes.md)