Warp zone
by Fabio Daniel "Sagaz" · in Torque Game Engine · 08/12/2006 (12:15 pm) · 1 replies
I'm no programmer, and I'm developing a game without one - just to study the engine and the scripting language. I'm trying to do a warp zone in my game, where if yo reach the borders of the game, you'll be "teleported" to the opposite border, facing to the center of the map (the same direction it was facing when going out of the map). If anyone playied Starfox 64 understands what I'm talking about, just reach the borders and you'll bep laced on the opposite and facing the center again. I tried the getPosition() function to this, but I doesnt work.
Can someone help me with this? That's my first attempt on TGE, and that's almost the only thing I want to do to have my game almost running.
Can someone help me with this? That's my first attempt on TGE, and that's almost the only thing I want to do to have my game almost running.
About the author
Associate Orion Elenzil
Real Life Plus
but there's some homework you'll have to do yourself.
1. learn how to add a Trigger to your mission. there's plenty of tutorials around.
2. learn how to create a new trigger datablock and how to use OnEnterTrigger(). again, tons of examples.
once you've done those,
create the following trigger datablock:
datablock TriggerData( YoullNeverEscapeTriggerDB ) { targetSpawnSphere = ""; };and add the following code to handle the OnLeaveTrigger() method for that trigger:
function YoullNeverEscapeTriggerDB::OnEnterTrigger(%this, %trigger, %obj) { echo("Now you are trapped," SPC %obj); } function YoullNeverEscapeTriggerDB::OnLeaveTrigger(%this, %trigger, %obj) { echo("And you will never escape!" SPC %obj); %trCn = %trigger.getWorldBoxCenter(); %orig = %obj.getTransform(); %v1 = vectorSub(%orig, %trCn); %v1 = vectorScale(%v1, 0.95); // just to be safe.. %v2 = vectorSub(%trCn, %v1); %finl = getWords(%v2, 0, 1) SPC getWords(%orig, 2, 6); %obj.setTransform(%finl); }- it may not be exactly what you want,
but it's close.
it teleports you to the "opposite" side of the trigger,
there the opposite side is the spot you hit if you flew straight thru the center.
it keeps your altitude and your orientation the same.
edit: - 0.95 was originally 0.5, which is way too safe. heck, 0.98 is probably fine too.