Leaving MissionArea
by Joe Melton · in Torque Game Engine Advanced · 12/18/2008 (1:18 am) · 2 replies
I am using TGEA 1.7.1 and have created code (based on Ken Finney's "Advanced 3D Game Programming All In One" book) to "warp" the player from one end of the MissionArea to the other when the player leaves the MissionArea. However, for some reason the function GameConnection::onLeaveMissionArea never gets called when I leave the MissionArea. Is this a deprecated function, or am I just using it incorrectly? Here is my code:
GameConnection::onLeaveMissionArea(%this)
{
// The control objects invoked this method when they
// move out of the mission area.
echo("Leaving mission area."); // THIS LINE NEVER RUNS WHEN LEAVING THE MISSION AREA
%missionAreaID = nameToID("MissionAreaObject");
%longitude = getWord(MissionAreaID.Area, 0);
%latitude = getWord(MissionAreaID.Area, 1);
%width = getWord(MissionAreaID.Area, 2);
%height = getWord(MissionAreaID.Area, 3);
%tf = %this.player.GetTransform();
%x = getWord(%tf, 0);
%y = getWord(%tf, 1);
%rotation = getWords(%tf, 3, 6);
if (%x < %longitude)
%x += %width;
else if (%x > (%longitude + %width))
%x -= %width;
if (%y < %latitude)
%y += %height;
else if (%y > (%latitude + %height))
%y -= %height;
%found = containerRayCast(%x SPC %y SPC "1000", %x SPC %y SPC "-1000",
$TypeMasks::TerrainObjectType, %this.player);
%foundID = %found.getID();
%newPosition = getWords(%foundID, 1, 3);
%this.player.SetTransform(%newPosition SPC %rotation);
}
I appreciate any assistance.
GameConnection::onLeaveMissionArea(%this)
{
// The control objects invoked this method when they
// move out of the mission area.
echo("Leaving mission area."); // THIS LINE NEVER RUNS WHEN LEAVING THE MISSION AREA
%missionAreaID = nameToID("MissionAreaObject");
%longitude = getWord(MissionAreaID.Area, 0);
%latitude = getWord(MissionAreaID.Area, 1);
%width = getWord(MissionAreaID.Area, 2);
%height = getWord(MissionAreaID.Area, 3);
%tf = %this.player.GetTransform();
%x = getWord(%tf, 0);
%y = getWord(%tf, 1);
%rotation = getWords(%tf, 3, 6);
if (%x < %longitude)
%x += %width;
else if (%x > (%longitude + %width))
%x -= %width;
if (%y < %latitude)
%y += %height;
else if (%y > (%latitude + %height))
%y -= %height;
%found = containerRayCast(%x SPC %y SPC "1000", %x SPC %y SPC "-1000",
$TypeMasks::TerrainObjectType, %this.player);
%foundID = %found.getID();
%newPosition = getWords(%foundID, 1, 3);
%this.player.SetTransform(%newPosition SPC %rotation);
}
I appreciate any assistance.
#2
MissionAreaObject *should* be the correct name to use. In the console I typed echo(MissionArea.getID()); and it returned nothing. However, when I typed echo(MissionAreaObject.getID()); it returned the correct ID as shown in the "explorer" view in the editor.
Thanks!
12/18/2008 (11:50 am)
Well that makes sense. I just used the empty function body that already existed in game.cs for GameConnection::onLeaveMissionArea in the Stronghold mission. I'll try out your suggestion and see if it works.MissionAreaObject *should* be the correct name to use. In the console I typed echo(MissionArea.getID()); and it returned nothing. However, when I typed echo(MissionAreaObject.getID()); it returned the correct ID as shown in the "explorer" view in the editor.
Thanks!
Torque Owner Gary Preston
function PlayerBody::onLeaveMissionArea( %this, %playerObj ) { ... }Edit: One further thing to check, is whether MissionAreaObject is the correct name to use. If you check player.cc in the engine source for the "checkMissionArea" function, you'll see which object it's using for mission bounds tests. I don't have the version of TGEA you have installed so can't say whether it's changed recently or not.