Game Development Community

Trying to learn

by J Sears · in Torque Game Engine · 10/28/2006 (2:43 pm) · 5 replies

I'm trying to learn and create one step at a time so I don't get overwhelmed and give up on it. One problem I'm finding is when I try to search for solutions I'm sure have been written about before I get way too many hits or results from 4 years ago. This makes learning a very slow process and so I decided to post a question here that I'm sure has a link somewhere that answers it.

I came up with a plan to help me learn a lot of the basics so I could continue from there it is what I like to call extremely simple rpg, add a new AI player, add a way to interact with him, have him open up an inventory/buy list, get something from him, choose it from player and have it added onto him, have player be able to hit with it or have armor effect with it, and keep building from there.

Sadly I'm working on step 2 interact with the npc/ai
I can figure out the logical steps to make such a feature but not how to code implement it.
I figure I would need to assign a key or make a gui button for interacting, and then set a radius for the ai to have to be within for it to work when clicked/pushed then have the ai bring up the dialog box and work from there.

I figure this is a very important thing for me to learn since it can be used in so many situations like doors etc. How do you set it up so that you have to be right next to something to make it work, anyone know a link to a spot where this is discussed?

#1
10/28/2006 (3:11 pm)
Hi J,

I haven't done this myself, but here is an idea. Have you heard of triggers? AFAIK, they are volumes which you can place and trigger an event when a GameBase derived object enters or leaves the volume.

A trigger provides you with three callbacks: onLeaveTrigger and onEnterTrigger (should be self explanatory) and onTickTrigger (which is called when the object remains in the trigger area). Maybe what you could do is place a trigger in front of the NPC, and then the trigger would check to see if the player has pressed the interact key in the onTickTrigger function. A possible way you could do that is to have a flag in the player object, for example InteractKeyPressed. Then, in your action map, when the user presses the interact key, you set InteractKeyPressed to true, and when the user releases, set it to false. The onTickTrigger would check for the status of this flag to determine if it should interact with your NPC.

One problem I see with this method is that it only works if the NPC is stationary, unless there is a way to attach a trigger volume to a moving object.

Here is a TDN article on the subject of triggers:
tdn.garagegames.com/wiki/WorldBuilding/MissionEditor/Creating_Triggers

As a final word, I just want to remind you that as I haven't encountered your problem before all that I've said is hypothetical.

--Amr
#2
10/28/2006 (7:26 pm)
Well I found this which was a great resource put it into 1.5 just fine so I will just fiddle around with it to figure out every bit of it http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=3531
#3
10/28/2006 (8:23 pm)
You could bind a key to a function and then in the function check the distance to the aiplayer using the following in script.
%tmpMinDist = 10;
%tmpDist = VectorDist(%player.position, %aiplayer.position);
if (%tmpDist<%tmpMinDist){
   //Do something to launch your dialog.
}
else {
   //Do nothing or output error message.
}
Echo out the value of %tmpDist to the console so you can test how close you want to %tmpMinDist be and then amend its value from 10 to what ever distance you want..
Came across this a couple of hrs ago when trying to find the closest of two objects and rememberd your post.
Hope this helps.
#4
10/29/2006 (9:34 am)
That should be a pretty easy way to do it peter thank you
#5
10/29/2006 (10:41 am)
That code example is fine, but too simple. You'll want to build upon it to make sure the player is actually facing that NPC, then you'll need to expand in case there are two npcs pretty close. But for starters that should get you off to a stard.