Triggering an Exploding Barrel Help
by TheHidden · in Game Design and Creative Issues · 04/14/2010 (9:48 pm) · 1 replies
I am trying to make a barrel explode when entering its triggered area. In order to get the barrel to explode manually, I have to type:
addBarrel();
Then I press “b” to make it go boom.
I am trying to find a way to make the trigger do all of that. I have tried different things in the trigger file but to no avail. Hopefully you could help make it so that when my player moves into range, barrel is set and explodes.
Thanks for any help.
Game path, basic template, is:
TGE_1_5_2exampledemogame
I will present the current barrel.cs and triggers.cs scripts.
Here is the barrel script:
TGE_1_5_2exampledemodatashapesbarrelbarrel.cs
// STATIC SHAPE INFORMATION
datablock StaticShapeData(barrel){
shapeFile = "demo/data/shapes/barrel/barrel.dts";
};
// AUDIO INFORMATION
new AudioDescription(barrelExplodeDesc){
volume = 1;
isLooping = false;
is3D = false;
referenceDistance = 1;
maxDistance = 25;
type = $SimAudioType;
};
new AudioProfile(barrelExplodeProf){
filename = "demo/data/shapes/barrel/barrel.ogg";
description = "barrelExplodeDesc";
};
// FUNCTIONS
function addBarrel(){
$barrel = new StaticShape(){
position = "40.3144 -12.6434 151.152";
rotation = "0 0 0 0";
scale = "0.05 0.05 0.05";
datablock = "barrel";
};
movemap.bind(keyboard, "b", explodeBarrel);
$hasExploded = false;
}
function explodeBarrel(){
if ($hasExploded == false){
alxPlay(barrelExplodeProf);
$barrel.playThread(0, "explode");
$hasExploded = true;
%barrelSmoke = new ParticleEmitterNode(){
position = "40.3144 -12.6434 151.152";
rotation = "0 0 0 0";
scale = "1 1 1";
datablock = barrelSmokeNode;
emitter = barrelSmokeEmitter;
velocity = 1;
};
}
}
Here is the trigger script:
TGE_1_5_2exampledemodatashapesbarreltrigger.cs
datablock TriggerData(BarrelTrigger){
tickPeriodMS = 1000;
};
function addTrigger(){
%obj = new Trigger() {
position = "40.3144 -12.6434 151.152";
scale = "1 1 1";
rotation = "0 0 1 0";
dataBlock = "BarrelTrigger";
polyhedron = "0 0 0 1 0 0 0 -1 0 0 0 1";
};
}
function BarrelTrigger::onEnterTrigger( %this, %trigger, %obj )
{
$TriggerInRange = true;
echo("In range.");
}
function BarrelTrigger::onLeaveTrigger( %this, %trigger, %obj )
{
$TriggerInRange = false;
echo("Out of range.");
}
addBarrel();
Then I press “b” to make it go boom.
I am trying to find a way to make the trigger do all of that. I have tried different things in the trigger file but to no avail. Hopefully you could help make it so that when my player moves into range, barrel is set and explodes.
Thanks for any help.
Game path, basic template, is:
TGE_1_5_2exampledemogame
I will present the current barrel.cs and triggers.cs scripts.
Here is the barrel script:
TGE_1_5_2exampledemodatashapesbarrelbarrel.cs
// STATIC SHAPE INFORMATION
datablock StaticShapeData(barrel){
shapeFile = "demo/data/shapes/barrel/barrel.dts";
};
// AUDIO INFORMATION
new AudioDescription(barrelExplodeDesc){
volume = 1;
isLooping = false;
is3D = false;
referenceDistance = 1;
maxDistance = 25;
type = $SimAudioType;
};
new AudioProfile(barrelExplodeProf){
filename = "demo/data/shapes/barrel/barrel.ogg";
description = "barrelExplodeDesc";
};
// FUNCTIONS
function addBarrel(){
$barrel = new StaticShape(){
position = "40.3144 -12.6434 151.152";
rotation = "0 0 0 0";
scale = "0.05 0.05 0.05";
datablock = "barrel";
};
movemap.bind(keyboard, "b", explodeBarrel);
$hasExploded = false;
}
function explodeBarrel(){
if ($hasExploded == false){
alxPlay(barrelExplodeProf);
$barrel.playThread(0, "explode");
$hasExploded = true;
%barrelSmoke = new ParticleEmitterNode(){
position = "40.3144 -12.6434 151.152";
rotation = "0 0 0 0";
scale = "1 1 1";
datablock = barrelSmokeNode;
emitter = barrelSmokeEmitter;
velocity = 1;
};
}
}
Here is the trigger script:
TGE_1_5_2exampledemodatashapesbarreltrigger.cs
datablock TriggerData(BarrelTrigger){
tickPeriodMS = 1000;
};
function addTrigger(){
%obj = new Trigger() {
position = "40.3144 -12.6434 151.152";
scale = "1 1 1";
rotation = "0 0 1 0";
dataBlock = "BarrelTrigger";
polyhedron = "0 0 0 1 0 0 0 -1 0 0 0 1";
};
}
function BarrelTrigger::onEnterTrigger( %this, %trigger, %obj )
{
$TriggerInRange = true;
echo("In range.");
}
function BarrelTrigger::onLeaveTrigger( %this, %trigger, %obj )
{
$TriggerInRange = false;
echo("Out of range.");
}
About the author
This account has not been used since 2010, but no way to delete it. :/
Torque Owner Donnie Hutson Jr