Collision2D
Namespace:
namespace Lenga\Engine\Core;
class Collision2D
Methods
fromNativeData
public static function fromNativeData(array $data)
Properties
gameObject
public ?GameObject $gameObject { get; }
The GameObject that contacted the callback receiver.
collider
public ?Component $collider { get; }
The collider that contacted the callback receiver.
selfGameObject
public ?GameObject $selfGameObject { get; }
The GameObject that received the callback.
selfCollider
public ?Component $selfCollider { get; }
The receiver-side collider involved in the contact.
otherGameObject and otherCollider
These remain available as aliases for the contacted object and collider.
Example
use Lenga\Engine\Core\Behaviour;
use Lenga\Engine\Core\Collision2D;
class DamageOnCollision extends Behaviour
{
public function onCollisionEnter(Collision2D $collision): void
{
Debug::log('Collided with: ' . $collision->gameObject?->name);
}
public function onCollisionStay(Collision2D $collision): void
{
// Called while contact continues.
}
public function onCollisionExit(Collision2D $collision): void
{
Debug::log('Stopped colliding with: ' . $collision->gameObject?->name);
}
}