Implementing NPC sound sensor
by Teddy Setiawan Wijaya · in Torque Game Builder · 07/03/2008 (3:24 am) · 7 replies
Hi!
In the game that I am prototyping, whenever player is running, sound will be emitted and nearby NPC should be able to hear it. One way of implementation that I can think of is having a circle shaped trigger mount to the player. This way when an NPC enter the trigger area, he/she can 'hear' the player.
The question that I have is: which one is better? (memory usage wise, performance wise, etc)
1. Create new trigger, add it to the scene, and mount it to player everytime player moves then delete the trigger when player stops
OR
2. The trigger is always there, however there is a flag that will be set or unset depending on player movement.
If anyone can offer any opinion, I'd be very grateful
Many thanks ;-)
In the game that I am prototyping, whenever player is running, sound will be emitted and nearby NPC should be able to hear it. One way of implementation that I can think of is having a circle shaped trigger mount to the player. This way when an NPC enter the trigger area, he/she can 'hear' the player.
The question that I have is: which one is better? (memory usage wise, performance wise, etc)
1. Create new trigger, add it to the scene, and mount it to player everytime player moves then delete the trigger when player stops
OR
2. The trigger is always there, however there is a flag that will be set or unset depending on player movement.
If anyone can offer any opinion, I'd be very grateful
Many thanks ;-)
#2
07/03/2008 (2:12 pm)
I second Mr. Ford's recommendation.
#3
No matter what you use, it is very, very important (for performance) that you use collision groups wherever possible.
07/03/2008 (2:57 pm)
I've never liked using triggers like this. I would be more inclined to use a "pickRadius".No matter what you use, it is very, very important (for performance) that you use collision groups wherever possible.
#4
For me using the trigger seem to be easier to debug (since you can set the collision bounds ON and see it in runtime) but I'll explore the pickRadius as well.
07/04/2008 (3:14 am)
James, Jason, Phillip thank you very much for the replies.For me using the trigger seem to be easier to debug (since you can set the collision bounds ON and see it in runtime) but I'll explore the pickRadius as well.
#5
Call this function and reposition the shape vector every time you call "pickRadius". You can do similar things for the other "pick" functions.
07/05/2008 (5:12 pm)
ShapeVectors are nice handy little tools:function debugPickRadius(%sceneGraph, %position, %radius)
{
// Create our shape vector
%shapeVector = new t2dShapeVector()
{
SceneGraph = %sceneGraph;
Position = %position;
Size = 2 * %radius SPC 2 * %radius;
LineColor = "1.0 0.5 1.0 1.0";
};
// Make a nice smooth circle
%segCount = 32;
%deltaAngle = mDegToRad(360) / %segCount;
for (%i = 0; %i < %segCount; %i++)
%polyList = trim(%polyList SPC mSin(%i * %deltaAngle) SPC mCos(%i * %deltaAngle));
%shapeVector.setPolyCustom(%segCount, %polyList);
return %shapeVector;
}Call this function and reposition the shape vector every time you call "pickRadius". You can do similar things for the other "pick" functions.
#6
It remind me of old Commandos game (by Pyro Studio) where if opted, player can see enemy's view cone..;-)
07/06/2008 (2:15 am)
Wow, real nice Phillip! now, I just need to work similar stuff for the view cone.It remind me of old Commandos game (by Pyro Studio) where if opted, player can see enemy's view cone..;-)
#7
07/06/2008 (8:22 am)
That Commandos game totally owns me. Sooo hard.
Associate James Ford
Sickhead Games