how can I make text appear when my player collides with a collision shape?

Godot Version

4.4.1

Question

I’m trying to make a pixel rpg, and in one of the scenes, the main character has to follow a specific path. I’m trying to make it so he stops and says something whenever he hits a barrier i’ve set
I’ve tried using both area2d, and static body 2d, im fairly new to godot and i’m not really sure how to fix this.

There are a variety of ways you could do this, but since (I assume…) you want to keep the player on the path, you might consider defining the path as a set of line segments and a maximum distance. It’s not particularly hard to do a “closest point on line segment” test for a point.

Each update, compare the player’s position with all the line segments using a “closest point on segment” test. Take the closest of those as the path section the player is “on”. If they’re further than the max acceptable distance from the line (thus “off the path”), you have:

  • that they’re off the path and should react
  • what direction to go in order to get back to the closest point on the path