EverestAPI / EverestAPI/Everest
Component that gives any entity Trigger-like behaviour
- Dominant language
- C#
- Stars
- 516
- Forks
- 106
- Avg merge
- 4d 9h
- Merged PRs (30d)
- 5
Description
### I am planning on implementing this myself
Yes
### Describe your request
Essentially, the code modder can add a component to their entity that gives the `OnEnter`/`OnStay`/`OnLeave` functionality as if it were a `Trigger`. This means modders will no longer need to manually track `CollideCheck`s across frames in the entity `Update`.
I've currently named the component `Triggerable` to be similar in naming to `Holdable`, and the actions `OnEnter`/`OnStay`/`OnLeave`, with their virtual invocation methods called `InvokeOnEnter`/`InvokeOnStay`/`InvokeOnLeave` in case the modder wants to override the component instead of assigning actions.
These actions (or method groups) can be passed into the constructor and/or assigned directly in the object initialiser. The first argument is an optional collider to use instead of the entity's Collider property.
Since colliders can be specified, this means multiple trigger regions can be assigned to the same entity if desired, each with different functionality.
This is an example where I've added three separate trigger regions to a gravity field, using different instantiation styles.
```cs
// custom hitbox, method groups
Add(new Triggerable(new Hitbox(16, Height, -16, 0), null, onStay, onLeave));
// custom hitbox, object initialiser
Add(new Triggerable(new Hitbox(16, Height, Width, 0)) {
OnEnter = _ => Audio.Play(SFX.char_gran_laugh_firstphrase),
OnLeave = player => player.Die(Vector2.Zero)
});
// default collider, object initialiser
Add(new Triggerable {
OnEnter = player => player.SuperBounce(Top)
});
private void onStay(Player player) => player.Sprite.Scale.X = 2;
private void onLeave(Player player) => player.Sprite.Scale.X = 1;
```
https://github.com/user-attachments/assets/e05540a3-8e26-409c-b22d-691422a60ad5
### Additional context
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.