Input, Collisions, and Triggers
This guide focuses on gameplay reactions: keys, collisions, and trigger zones.
Input Methods You Will Use Most
The Input facade exposes common checks:
Input::isKeyPressed(...)Input::isKeyDown(...)Input::isKeyUp(...)Input::getAxis(...)
Prefer KeyCode enum values over hardcoded strings in gameplay code.
Example: Movement Input
<?php
use Sendama\Engine\Core\Behaviours\Behaviour;
use Sendama\Engine\Core\Vector2;
use Sendama\Engine\IO\Input;
use Sendama\Engine\IO\Enumerations\KeyCode;
final class PlayerMove extends Behaviour
{
public function onUpdate(): void
{
$motion = new Vector2();
if (Input::isKeyPressed(KeyCode::a)) {
$motion->setX(-1);
}
if (Input::isKeyPressed(KeyCode::d)) {
$motion->setX(1);
}
$this->getTransform()->translate($motion);
}
}
Collision And Trigger Hooks
Use these hooks in behavior scripts:
onCollisionEnter()onCollisionStay()onCollisionExit()onTriggerEnter()onTriggerStay()onTriggerExit()
Example: Trigger A Door
<?php
use Sendama\Engine\Core\Behaviours\Behaviour;
use Sendama\Engine\Physics\Interfaces\CollisionInterface;
final class ExitDoor extends Behaviour
{
public function onTriggerEnter(CollisionInterface $other): void
{
if ($other->getGameObject()->hasTag('player')) {
loadScene('Level 02');
}
}
}
Reliable Trigger Pattern
- put trigger behavior on door/portal object
- ensure player object has expected tag
- run into trigger in play mode
- verify callback runs with log output
Debug Checklist
If events do not fire:
- verify collider setup on both interacting objects
- verify active state of objects
- verify tags and callback logic
- verify scene object is not deactivated