feat: ICollider2D Action Calls

This commit is contained in:
Syntriax 2024-01-27 19:22:59 +03:00
parent 0ba6913a61
commit 309c8db6e1
2 changed files with 8 additions and 2 deletions

View File

@ -6,8 +6,8 @@ namespace Syntriax.Engine.Physics2D.Abstract;
public interface ICollider2D : IBehaviour, IAssignableTransform
{
Action<ICollider2D, ICollider2D>? OnCollisionPreResolve { get; set; }
Action<ICollider2D, ICollider2D>? OnCollisionResolved { get; set; }
Action<ICollider2D, CollisionDetectionInformation>? OnCollisionPreResolve { get; set; }
Action<ICollider2D, CollisionDetectionInformation>? OnCollisionResolved { get; set; }
IRigidBody2D? RigidBody2D { get; }

View File

@ -62,6 +62,9 @@ public class PhysicsEngine2D : IPhysicsEngine2D
if (collisionDetector.TryDetect(colliderX, colliderY, out CollisionDetectionInformation information))
{
colliderX.OnCollisionPreResolve?.Invoke(colliderX, information);
colliderY.OnCollisionPreResolve?.Invoke(colliderY, information);
Vector2D displacementVector = information.Normal * information.Penetration;
@ -89,6 +92,9 @@ public class PhysicsEngine2D : IPhysicsEngine2D
information.Left.Recalculate();
information.Right.Recalculate();
colliderX.OnCollisionResolved?.Invoke(colliderX, information);
colliderY.OnCollisionResolved?.Invoke(colliderY, information);
}
}
}