Moving a dif thru code
by Mike Rowley · in Technical Issues · 10/27/2006 (3:08 pm) · 11 replies
I have several gates in my game. Each one starts out closed. When a player picks up a coin, it opens the gate so they can continue on thru the level.
Here's what I have so far that works:
In item.cs I have:
This code works. The problem is, I don't know how to fix this so that it works on different gates.
Example:
IE:
or would it be better to use a switch statement?
I don't know. (and don't quite know how to make the item.cs file check for the coin number)
Any help is appreciated.
Here's what I have so far that works:
function MoveShape()
// ----------------------------------------------------
// moves the Gate to it's new position.
// ----------------------------------------------------
{
Gate1.getTransform(); //Getting current location
//Sets new location
Gate1.setTransform("-145.244 199.162 46.3842 0 0 1 3.15001");
}In item.cs I have:
// Inform the client what they got.
if (%user.client)
messageClient(%user.client, 'MsgItemPickup', '\c0You picked up %1', %this.pickupName);
MoveShape(); //Open the gateThis code works. The problem is, I don't know how to fix this so that it works on different gates.
Example:
Area1-->Pick up coin1-->open Gate1 Area2-->Pick up coin2-->open Gate2What I have only works for 1 gate. I have 4 gates that open the same way, but are in different areas of the map. Do I make the function full of "if" statements??
IE:
if coin1
open Gate1
if coin2
open Gate2
else return();?????or would it be better to use a switch statement?
I don't know. (and don't quite know how to make the item.cs file check for the coin number)
Any help is appreciated.
#2
I get no errors, but no action eather.
Here's my code if you can figure out what I did wrong.
10/27/2006 (4:46 pm)
Figured out what a parse error was... :blush:I get no errors, but no action eather.
Here's my code if you can figure out what I did wrong.
function MoveShape()
// ----------------------------------------------------
// moves the Gate to it's new position.
// ----------------------------------------------------
{
%CId = art1.getID();
%CId= art2.getID();
%GId = Gate1.getID();
%GId = Gate2.getID();
%shape = %CId && %GId;
%xfrm = %shape.getTransform();
%lx = getword(%xfrm,0); // get the current transform values
%ly = getword(%xfrm,1);
%lz = getword(%xfrm,2);
%lz += %dist; // adjust the x axis position
%shape.setTransform(%lx SPC %ly SPC %lz SPC "0 0 1 0");
// Gate1.getTransform(); //Getting current location
//Sets new location
// Gate1.setTransform("-145.244 199.162 46.3842 0 0 1 3.15001");
}
function DoMove()
// ----------------------------------------------------
// a function to tie together the instantiationinstantion
// and the movement in one easy to type function
// call.
// ----------------------------------------------------
{
MoveShape(%shape,5);
}
#3
10/27/2006 (5:01 pm)
Hmm..I'd probably use a dts rather than a dif.
#4
10/27/2006 (5:06 pm)
Quote:Hmm..I'd probably use a dts rather than a difI thought about that. I have yet to be able to make a dts tho.
#5
I would instead use triggers. Sample code:
10/27/2006 (8:06 pm)
Yeah it won't work with difs that way. See the problem is that the item (key) is executed before the mission file. Thus there is no dif object to get an ID from when the item needs it.I would instead use triggers. Sample code:
datablock TriggerData(KeyTrigger)
{
tickPeriodMS = 500;
};
function CoinTrigger::onEnterTrigger(%this,%trigger,%obj)
{
%coin = %trigger.parent.getDataBlock().getName();
switch$ ( %coin )
{
case "Coin1":
%gate = nameToId("Gate1");
%gate.setTransform("-145.244 199.162 46.3842 0 0 1 3.15001");
case "Coin2":
// Get the gate ID and do same as above
}
}
function CoinTrigger::onLeaveTrigger(%this,%trigger,%obj)
{
// Do nothing
}
function CoinTrigger::onTickTrigger(%this,%trigger)
{
// Do nothing
}
// Replace with your datablock etc. etc.
datablock ItemData(Coin1)
{
category = "Misc";
shapeFile = "~/data/shapes/logo/torque_logo.dts";
hasLight = true;
lightType = PulsingLight; // NoLight, ConstantLight, PulsingLight
lightRadius = 20;
lightColor = "0.0 0.0 1.0 1";
lightOnlyStatic = false;
};
function Coin1::onAdd(%data, %obj)
{
Parent::onAdd(%data, %obj);
%obj.trigger = new Trigger()
{
dataBlock = CoinTrigger;
polyhedron = "0 0 0 1 0 0 0 -1 0 0 0 1";
scale = "5 5 5";
parent = %obj;
};
MissionCleanup.add( %obj.trigger );
// If you increase the trigger size, you'll need to adjust those first two word's
// to half of the corresponding scale values. Third word is the z axis which is whatever you want.
%pos = MatrixMulPoint(%obj.getTransform(), "-2.5 2.5 -0.1");
%obj.trigger.setTransform(%pos SPC rotFromTransform(%transform));
}
function Coin1::onPickup(%this,%obj,%user,%amount)
{
// Do not add the coin to inventory.
// Inform the client what they got.
if (%user.client)
messageClient(%user.client, 'MsgItemPickup', '\c0You have opened a gate with %1', %this.pickupName);
%obj.delete();
%obj.trigger.delete();
}
#6
Thanks for your help. :)
10/28/2006 (7:13 am)
When I couldn't force it to work, I figured there was a problem and added triggers. Thanks for your help. :)
#7
This code just raises the gate by 4. That part works. My problem is in the rotation. It's turning about 80 degrees off the Z axis. It should be going strait up. Anyone have a clue why it would be turning?
Question #2
In the rotation, what is the -1?? (0 0 -1 88.5853)
10/28/2006 (7:42 pm)
Ok, still having a few problems with this.Parent::onEnterTrigger(%this,%trigger,%obj);
Gate.getTransform(); //Getting current location
//Sets new location
Gate.setTransform("114.797 512.117 45.9842 0 0 -1 88.5853");
echo("Your gate is now open");
// End of trigger code
//mission code.
Gate
position = "114.659 512.102 41.1842";
rotation = "0 0 -1 88.5853";This code just raises the gate by 4. That part works. My problem is in the rotation. It's turning about 80 degrees off the Z axis. It should be going strait up. Anyone have a clue why it would be turning?
Question #2
In the rotation, what is the -1?? (0 0 -1 88.5853)
#8
This is because.. I am not rembering which uses what but.. setRansform uses radians while the object as in the mission is using degrees for rotation. So it gets messed up because the are not interchangable, you have to convert.
10/29/2006 (11:11 am)
Your better off setting it like so:%trans = nameToId("Gate").getTransform();
%rot = getWord(%trans, 3) SPC getWord(%trans, 4) SPC getWord(%trans, 5) SPC getWord(%trans, 6);
nameToId("Gate").setTransform("114.797 512.117 45.9842" SPC %rot );This is because.. I am not rembering which uses what but.. setRansform uses radians while the object as in the mission is using degrees for rotation. So it gets messed up because the are not interchangable, you have to convert.
#9
10/29/2006 (3:52 pm)
Hmm, ok. I'll give that a try. Thanks for the reply.
#10
10/29/2006 (4:52 pm)
Just noticed I didn't answer the 2nd question. The -1 in that example is telling the world to rotate the object on the z axis negative 88.5853 degrees. So the 3 numbers in front of that 88 are the axis and really are just switches that are either 0 or 1 or -1
#11
The second one answers my question. :)
10/29/2006 (7:53 pm)
Thankyou for both answers. The first one makes since and works. The second one answers my question. :)
Torque Owner Badguy
coin1.gateId = Gate1.getID()
then you can simply:
MoveShape(coin1.gateId)
which might look a little like:
Gate = gateId // however you resolve id to object, I cannot remember.
Gate.getTransform(); //Getting current location
Gate.setTransform("-145.244 199.162 46.3842 0 0 1 3.15001");
something like that.
should not be too bad of a hack to place the key's gate Id on the key.
Edit:
oh yea, the id Is the object, no need to do a resolve there.