Game Development Community

Non entities interactions.

by Kyrah Abattoir · in Torque 3D Beginner · 02/12/2013 (5:51 am) · 4 replies

So this is something i've seen used in a few games, unity and garry's mod. Instead of creating an entity that can be interacted with, such as a complete NPC, control panel or object that can be picked up, those games where using a static "shape", and when the player attempted to interact with it, it would attempt to get the name of the 3D model used and decide what UI to open.

Example: A bank teller

You have an animated static object representing your bank teller behind his counter, and when the game detect that the player pushed the use key, and that the aiming trace intersect with "bankteller.dae", it opens the global bank interface.

Example: Health kit
You have a static object representing a medikit, when the player collides with it, it's model name is extracted and HPs are added to the player, the object is then removed from the game world.

Is there a real performance gain in making the player side of the code detect these "non entities" instead of actually using a properly scripted NPC or scripted object?

#1
02/12/2013 (7:25 am)
I am not totally clear yet on everything you mean here, but maybe a few examples on the evolution on what I am doing will help.
I at first had a static NPC kind of like the bankteller that had a trigger that interacted when inside to pull up a name gui by the crosshairs. If the player pressed enter then it will load the NPC dialog gui. This Gui can be anything from a lockpick gui, treasure chest gui etc. based on what the obj.interact field has in it.
Now I have wondering NPC's that my modified gun script will detect. The gun model has been swapped with an invisible square (with the appropriate nodes like mount0 etc)for the character's bare hands mode.

This gun does a constant scan linked to the onReady sequence. The onFire sequence will initiate pulling up the gui in accordance to what type of object it is. Today I will be coding the ability to pick fruit and herbs from various plants based on it.
#2
02/12/2013 (7:36 am)
Yeah it's more or less what i ment, in the sense that the object you are interacting with isn't actually interacting with the player, rather, it's the player object detecting what is being interacted with.
#3
02/12/2013 (9:50 am)
As far as performance, it shouldn't make any noticeable difference. In T3D I'd do a raycast and find out what I hit, then do something; that something might be to get the shape file of the object I hit, or it might be to call a method on the object, or it might be to call a function that does something.

In T3D, there is a slight advantage as far as ease of coding scripts if you simply call a method on the object hit; if you assign a class to the object you can call %target.hitMethod() and the class of the object will handle the hit correctly automatically, avoiding large if else or switch statements.
#4
02/12/2013 (3:39 pm)
Quote:the class of the object will handle the hit correctly automatically, avoiding large if else or switch statements
Yes! Datablocks are great for this.