clarifying some stuff in motion engine revision
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
41bb27b7d2
commit
4a947247ec
|
@ -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.
|
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**:
|
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.
|
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**
|
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.
|
This is pretty straightforward. We'll use this message to set an entity's position.
|
||||||
|
|
||||||
|
Now we can send these messages in **MotionEngine**.
|
||||||
|
|
||||||
```cs
|
```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.
|
Now let's handle those collision messages.
|
||||||
|
|
Loading…
Reference in New Issue