mirror of
https://github.com/hanzoai/ProjectTinySamples.git
synced 2026-09-24 00:01:34 +00:00
28 lines
801 B
C#
28 lines
801 B
C#
using Unity.Entities;
|
|
using Unity.Jobs;
|
|
|
|
namespace TinyPhysics.Systems
|
|
{
|
|
/// <summary>
|
|
/// Detect if the character is grounded
|
|
/// </summary>
|
|
|
|
[UpdateAfter(typeof(CollisionSystem))]
|
|
public class GroundedSystem : SystemBase
|
|
{
|
|
protected override void OnUpdate()
|
|
{
|
|
Entities.ForEach((ref Collideable collideable, ref Character character) =>
|
|
{
|
|
// update grounded value
|
|
bool isColliding = collideable.CollisionEntity != Entity.Null;
|
|
character.isGrounded = isColliding ? character.isGrounded = true : character.isGrounded = false;
|
|
|
|
// Consume collision
|
|
collideable.CollisionEntity = Entity.Null;
|
|
}).WithStructuralChanges().Run();
|
|
}
|
|
}
|
|
|
|
}
|