I am making a 2d open map game. In my game I need the main character to be able to interact with NPC’s around the map. Right now I am using this code to track when the NPC and the main character are touching and when the player hits the interact key (enter):
function on_message(self, message_id, message, sender)
if message_id == hash("collision_response") then
self.aretheytouching = true
end
function on_input(self, action_id, action)
if action_id == hash("enter") then
if self.aretheytouching then
msg.post("/testbox", "enable")
end
end
end
The test box is what I want to trigger when they touch and interact.
The issue I have is once the player touches the NPC once, self.aretheytouching is always true, so if they player touches the NPC and walks away, they could still cause the textbox to enable. I am wondering if there is a better way to track if the NPC and player are touching (maybe a timer of sorts).
Thanks in advance!