Intro to 3D Game Development

0 of 193 lessons complete (0%)

Scripting Part 3: Finishing the Game Loop

Check if the Entity is a Player

You don’t have access to this lesson
Please register or sign in to access the course content.

Most of the time, you will only want players to activate your trigger events, and now that we have a way to access the entity, we can narrow it down to only listen for players, using the power of tags, which we’ll discuss in a later step.

We’ll also delete the onTriggerStay and onTriggerExit functions now, since in this case we only need to know when the player enters an area.

  1. Delete the onTriggerStay and onTriggerExit functions.
  2. In the onTriggerEnter functions, create an if-statement
  3. Give the if-statement the condition something.tags.has(“player”)
  4. Make sure the closing } comes after the console.log