Swimming Zone Trigger
by Orion the Hunter · in Torque Game Builder · 08/27/2012 (3:12 pm) · 5 replies
Hello,
Does anyone know of a tutorial on how to make a swimming zone under water for my platformer?
The following things I would like to accomplish are:
Make a trigger with onEnter and onLeave callbacks which tell the game when to make the actor swim,
•Slow the gravity down to be like water,
•Muffle the music or a clever thing could be making it so that there has always been a version of the music playing that is muffled but it is at zero volume, until you enter the water zone, when it turns the volume of the main music off and turns the volume of the water music on,
•Make swimming animation states,
•And having bubble particles that spawn when you move around a bit.
Thanks!
Does anyone know of a tutorial on how to make a swimming zone under water for my platformer?
The following things I would like to accomplish are:
Make a trigger with onEnter and onLeave callbacks which tell the game when to make the actor swim,
•Slow the gravity down to be like water,
•Muffle the music or a clever thing could be making it so that there has always been a version of the music playing that is muffled but it is at zero volume, until you enter the water zone, when it turns the volume of the main music off and turns the volume of the water music on,
•Make swimming animation states,
•And having bubble particles that spawn when you move around a bit.
Thanks!
#2
Help?
Here's my code:
08/28/2012 (10:24 am)
Hmm. I edited it but did not get a good response. It says "cannot find function getpositionx()" and "cannot find function getpositiony()"Help?
Here's my code:
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// Torque Game Builder
// Copyright (C) GarageGames.com, Inc.
//
// behaviour written by Andy Hawkins 2011
//-----------------------------------------------------------------------------
/*
1) Add a global to point to your player, called $player.
2) Create a sceneObject, named MyTrigger and drop this behavior on it.
3) Turn off all collisions for this.
*/
if (!isObject(SwimmingZoneTrigger))
{
%template = new BehaviorTemplate(SwimmingZoneTrigger);
%template.friendlyName = "Swimming Zone Trigger";
%template.behaviorType = "System";
%template.description = "Preform actions when the player is in the water.";
}
function SwimmingZoneTrigger::onLevelLoaded(%this)
{
%this.owner.enableUpdateCallback();
%this.insideTrigger = false;
}
function SwimmingZoneTrigger::onUpdate(%this)
{
// get the extents of this scene object
%area = %this.owner.getArea();
%minX = getword(%area, 0);
%minY = getword(%area, 1);
%maxX = getword(%area, 2);
%maxY = getword(%area, 3);
// get the player position
%x = %this.owner.getPositionX();
%y = %this.owner.getPositionY();
// test to see if the centroid of the player is inside this.
if (%x >= %minX && %x <= %maxX && %y >= %minY && %y < %maxY )
{
%this.insideTrigger = true; // yes it is
}
else
{
%this.insideTrigger = false; // no it isn't
}
// resolve trigger events
if (%this.insideTrigger && %this.owner.getName() $= "Exit" )
{
startSwimming();
}
// turn off the prompt text
if (%this.insideTrigger == false && %this.owner.getName() $= "Exit" )
{
stopSwimming();
}
}
function::SwimmingZoneTrigger::OnEnter(%this)
{
startSwimming()
}
function::SwimmingZoneTrigger::OnLeave(%this)
{
stopSwimming()
}
function startSwimming()
{
canvas.pushdialog(mainmenugui);
}
//And stop SwimmingZoneTrigger actions!
function stopSwimming()
{
canvas.popdialog(selectlevelgui);
}
#3
08/29/2012 (1:31 am)
The problem is on line 39 and 40. You need it to point to a global referencing the player. Check the original code I posted. It uses $player.getPosition...
#4
Thanks for the help!
08/29/2012 (10:41 am)
Sorry... Still not working and still giving me two pairs of the can't find function errors (one for x, one for y) a second and counting! It just keeps sending the same error continuously! Here is what my code is so far://-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// Torque Game Builder
// Copyright (C) GarageGames.com, Inc.
//
// behaviour written by Andy Hawkins 2011
//-----------------------------------------------------------------------------
/*
1) Add a global to point to your player, called $player.
2) Create a sceneObject, named MyTrigger and drop this behavior on it.
3) Turn off all collisions for this.
*/
if (!isObject(SwimmingZoneTrigger))
{
%template = new BehaviorTemplate(SwimmingZoneTrigger);
%template.friendlyName = "Swimming Zone Trigger";
%template.behaviorType = "System";
%template.description = "Preform actions when the player is in the water.";
}
function SwimmingZoneTrigger::onLevelLoaded(%this)
{
%this.owner.enableUpdateCallback();
%this.insideTrigger = false;
}
function SwimmingZoneTrigger::onUpdate(%this)
{
// get the extents of this scene object
%area = %this.owner.getArea();
%minX = getword(%area, 0);
%minY = getword(%area, 1);
%maxX = getword(%area, 2);
%maxY = getword(%area, 3);
// get the player position
%x = $player.getPositionX();
%y = $player.getPositionY();
// test to see if the centroid of the player is inside this.
if (%x >= %minX && %x <= %maxX && %y >= %minY && %y < %maxY )
{
%this.insideTrigger = true;
}
else
{
%this.insideTrigger = false;
}
// resolve trigger events
if (%this.insideTrigger && %this.owner.getName() $= "Exit" )
{
startSwimming();
}
// turn off the prompt text
if (%this.insideTrigger == false && %this.owner.getName() $= "Exit" )
{
stopSwimming();
}
}
function startSwimming()
{
canvas.pushdialog(mainmenugui);
}
function stopSwimming()
{
canvas.popdialog(mainmenugui);
}Thanks for the help!
#5
Now for #2! Is there a way to have two songs playing at the same time?
09/12/2012 (12:44 pm)
Alright, #1√Now for #2! Is there a way to have two songs playing at the same time?
Torque Owner Gofacial
Gofworks
//----------------------------------------------------------------------------- //----------------------------------------------------------------------------- // Torque Game Builder // Copyright (C) GarageGames.com, Inc. // // behaviour written by Andy Hawkins 2011 //----------------------------------------------------------------------------- /* 1) Add a global to point to your player, called $player. 2) Create a sceneObject, named MyTrigger and drop this behavior on it. 3) Turn off all collisions for this. */ if (!isObject(MyOwnTrigger)) { %template = new BehaviorTemplate(MyOwnTrigger); %template.friendlyName = "User Defined Trigger."; %template.behaviorType = "System"; %template.description = "Check to see if player has entered area."; } function MyOwnTrigger::onLevelLoaded(%this) { %this.owner.enableUpdateCallback(); %this.insideTrigger = false; } function MyOwnTrigger::onUpdate(%this) { // get the extents of this scene object %area = %this.owner.getArea(); %minX = getword(%area, 0); %minY = getword(%area, 1); %maxX = getword(%area, 2); %maxY = getword(%area, 3); // get the player position %x = $player.getPositionX(); %y = $player.getPositionY(); // test to see if the centroid of the player is inside this. if (%x >= %minX && %x <= %maxX && %y >= %minY && %y < %maxY ) { %this.insideTrigger = true; // yes it is } else { %this.insideTrigger = false; // no it isn't } // resolve trigger events if (%this.insideTrigger && %this.owner.getName() $= "Exit" ) { // TODO add your outside trigger code here } // turn off the prompt text if (%this.insideTrigger == false && %this.owner.getName() $= "Exit" ) { // TODO add your inside trigger code here } }