-
Notifications
You must be signed in to change notification settings - Fork 2
Mesh Collider
extends Collider
implements N/A
Mesh Collider is a component which inherits from Collider. It is used to prevent collision between multiple entities containing different Mesh components. The current iteration of this uses the recast algorithm to detect collisions.
Accessibility | Type | Field Name | Description |
---|---|---|---|
private | List | collision | the algorithm is looped multiple times to reduce error. To save time, colliding nodes on a given iteration are stored in this list, the next iteration will only be looped over this list |
Accessibility | Return Type | Method Name | Description |
---|---|---|---|
public | List | checkCollision | determine if any nodes are colliding from a given list of nodes. Returns nodes found to have collided. |
private | Vector2f | getClosestPoint | with a node and a mesh given, returns the point on the mesh closest to the node |
public | Vector2f | setNodePositionToClosestEdge | node is moved to closest point on edge (can return this point if needed) |
This class references some utility functions seen in the Collision2D class and (Mesh class.
Since the specific collision detection algorithms are found in [Mesh](Mesh, more detail can be found there. For every node in the Nodes list and for every Entity in the entities list (both lists inherited from the base class), the raycast algorithm is used to check if the node is within the entity's mesh. If the node is part of that entity's mesh, it is skipped. If a collision is found, a response is prompted (see collision response below) and it is added to a list of nodes that was found to have collided.
After a collision is detected, the next step is to respond to that collision. The closest position is then calculated by determining the shortest perpendicular distance to the node from each of the mesh's edges. The node is then moved to that position.
To ensure our colliding nodes are no longer colliding, the algorithm is re-run, limiting the scope to only colliding nodes. This process repeats for up to 5 times.