Interaction with NPC's and inanimate objects

I am looking for help in simplifying the interaction between a player controlled character and NPCs. Currently I am trying to have the player character walk up to an npc then press a button to talk to said npc. The way I have been using is to search the pixels in a set area in front of the player for objects. If it finds an any objects it will check them all for the ability to interact with them. If one comes up as able to interact with, then the action will happen (in this case, pops a chat bubble).

I am mainly looking for other ideas on how to handle the search for the npc and the interaction. Any ideas or help will be appreciated. [import]uid: 39394 topic_id: 9881 reply_id: 309881[/import]

Well, depends how many NPCs you have in a level.
If its not many you could just do a straight search against each of them, using their position and size as a rough means of testing proximity (you’d want to add to this size-wise though, you want to test if you are close, not if you are pratically in their pants!).

As for how to deal with them once they are found, you could make them objects (as in OO) or simple tables with properties, one of which would be something like:

object = {}
object.actions = { “talk”, “fight”, “slap” }

etc. Then just see what actions that user has available, and go from there.
Depending on how much interaction you want with the NPC, this can turn into a very complicated subject :slight_smile:

PS this isn’t how I’d do it, but my way would involve a lot more setting up and explaining. [import]uid: 46639 topic_id: 9881 reply_id: 36020[/import]