On Player Stay Command Trigger
Okay this isn’t much of an add-on, but I’ve had a couple people ask me how to make like area effect damaging from the environment. This can be done using the Command Trigger, but it needs a little help:
Purpose: Say you want a healing zone, or mana replenishing zone or environment / spring water, you run into the water, you start healing. Or run across lava, you start burning, etc… And if you continue to stand there… you keep healing or burning, etc…
M2D originally only had Enter/Exit, so when you entered you could trigger something, and exit, but not a super clean way (unless I’m mistaken!!!) to just continually have an effect run.
So, 2 lines of simple code:
In CommandTrigger.cs
Add:
public enum EActivationEvent
{
OnPlayerStayTrigger,
}
Then at the bottom near OnMovable and OnInteract:
private void OnTriggerStay2D(Collider2D collider) => AttemptExecution(EActivationEvent.OnPlayerStayTrigger, collider.gameObject);
You can then setup a Temporal Heal/Dmg effect, or whatever, that continues to pop on the player, however you want to wire it up. Example shown of how I setup my mana circle. Just drop a 2D collider + Command Trigger on a gameobject, and good to go.


💬 Comments (3)
Want to continue the conversation?