From 4a947247ec50f8ced12fd2b8757655f0751241ab Mon Sep 17 00:00:00 2001 From: Evan Hemsley Date: Tue, 21 Jul 2020 15:27:21 -0700 Subject: [PATCH] clarifying some stuff in motion engine revision --- content/pong/ball/bouncing/motion_engine.md | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/content/pong/ball/bouncing/motion_engine.md b/content/pong/ball/bouncing/motion_engine.md index 9acab86..579c253 100644 --- a/content/pong/ball/bouncing/motion_engine.md +++ b/content/pong/ball/bouncing/motion_engine.md @@ -10,7 +10,7 @@ First, we add entities with CollisionComponents to the SpatialHash. Next, we consolidate MotionMessages by their entities to get a total movement value for each entity. -Finally, we go over all entities with a PositionComponent and CollisionComponent, and sweep over the distance it has moved to check for collisions. If any entity overlaps, we dispatch a CollisionMessage. +Finally, we go over all entities with a PositionComponent and CollisionComponent, and sweep over the distance it has moved to check for collisions. If any entity would overlap with another, we adjust its movement to prevent it from overlapping and dispatch a CollisionMessage. First let's create a CollisionComponent. In **PongFE/Components/CollisionComponent.cs**: @@ -95,7 +95,7 @@ Next, let's consolidate our MotionMessages per Entity. ... ``` -This is where our *IHasEntity* optimization comes in - it allows us to use the **ReadMessagesWithEntity** method. +This is where our *IHasEntity* optimization comes in. It allows us to use the **ReadMessagesWithEntity** method. Finally, let's implement our sweep test. @@ -132,9 +132,13 @@ Finally, let's implement our sweep test. } ``` -First we sweep in a horizontal direction, and then in a vertical direction, returning the positions where collisions occurred. This means that objects won't awkwardly stop in place when they touch something. +Here we use Bonk's **SweepTest** functionality. A sweep test moves a rectangle along a vector, checking for collisions along the movement of the sweep. First we sweep in a horizontal direction, and then in a vertical direction, returning the positions where collisions occurred. This means that objects won't awkwardly stop in place when they touch something. -Now that we have a mechanism for detecting sweep hits, we can send out our CollisionMessage and UpdatePositionMessage. +{{% notice note %}} +In the future you might want to change how the sweep tests resolve a position, and this would certainly be possible using this system. You could have different components like **SlideOnCollisionComponent** or **StickOnCollisionComponent**, for example, that would affect the returned sweep position. +{{% /notice %}} + +Now that we have a mechanism for detecting sweep hits, we can send out a CollisionMessage and UpdatePositionMessage. In **PongFE/Messages/CollisionMessage.cs** @@ -191,6 +195,8 @@ namespace PongFE.Messages This is pretty straightforward. We'll use this message to set an entity's position. +Now we can send these messages in **MotionEngine**. + ```cs ... @@ -226,6 +232,6 @@ This is pretty straightforward. We'll use this message to set an entity's positi ... ``` -Putting it all together. We go over everything with a Position and Collision component, sweep test for collisions, and send appropriate Collision and UpdatePosition messages accordingly. +Here, we go over everything with a Position and Collision component, sweep test for collisions, and send appropriate Collision and UpdatePosition messages accordingly. Now let's handle those collision messages.