Skip to content

TriggerComponent

Michele edited this page Oct 13, 2019 · 3 revisions

Description of the Trigger Component

The TriggerComponent is a component that allow to check if a RigidBodyComponent is inside it or not. As it's for the RigidBodyComponent it could be built on multiple shapes, but for simplicity right now there's only BoxTriggerComponent.

Once built and placed, you must check your own if a RigidBodyComponent is inside it. The best way to do it is placing a check on the update function.

Example

The best example of this is in SimpleGame, that has the RespawnTrigger. The RespawnTrigger has a vector of RigidBodyComponent to check. Every frame it check if each one of them is inside or not. If a RigidBodyComponent is inside it check the GameObject name, if is a Crate it calls kill(), if is the player it calls respawn().

Notice: you know only when a RigidBodyComponent is inside or not. It's up to you to manage and keep the reference between the RigidBodyComponent and it's GameObject. Otherwise you can use:

SGameObject* SComponent::get_owner()

from any component.