Game Development Community

How would I add a dts as a child of a dif?

by Mike Rowley · in Torque Game Engine · 02/04/2007 (11:55 am) · 3 replies

I am working on a sliding door that has glass in it. I have the door (dif) and I have the glass (dts). Both look great together. I put the door in with my movement script, and the door moves as expected. I put the glass in, but it stays put. (as expected). I added code in my trigger to move the glass with the door, but That gave me a new problem. The glass collision box moves with the door, leaving the glass behind. (unexpected).
How would I make the dts glass a child of the dif so that it moves with the dif?
I have tried alt/click on the door object and adding the glass, but that didn't work.
Anyone have an idea?

#1
02/06/2007 (4:43 am)
Hi Mike, sorry, I cannot really help you, I'm much more focused on content creation at the moment and I'm not very good in scripting.
I just wanna ask you if can you give me an idea of your script to move the door since I need something similar...

Further that... I read something about that SIMGroup are also usefull for scripting purposes...
Maybe is it possible to put the DIF and the DTS in the same SIMGroup and make the script working on the SIMGroup?
#2
02/06/2007 (5:00 am)
I think the root of the problem is that you're moving a dif object. Torque doesn't deal with moving dif objects very well. IIRC, the collision detection routines concerning dif objects assume that it doesn't move, so that objects that collide against the dif are detected, while objects that the dif collides against if it moves are not. This is one of the things that makes elevators such a pain in Torque, btw.

In any case, if you make both the door and the glass a dts object (maybe just one dts object containing both), it should work fine. Create an animation of the door opening, make sure to animate the door's collision box so players can walk through it when it's open, then call the animation in either forward or reverse order to open and close the door.

There are a number of threads and resources concerning doors that outline how to do this.
#3
02/07/2007 (3:29 pm)
Hi Joz, thanks anyway. :)

The code for moving the dif is already on the forum in another thread where I battled getting it to work, but here is some of the code. It's actually quite simple.

copy "server/scripts/trigger.cs and rename it to something more discriptive to your object.

inside, find "datablock TriggerData(DefaultTrigger)" at the top. Change "DefaultTrigger" to a more discriptive name, and all instances of that name to match.

Then, in both onEnterTrigger add the following:
// This method is called whenever an object enters the %trigger
   // area, the object is passed as %obj.  The default onEnterTrigger
   // method (in the C++ code) invokes the ::onTrigger(%trigger,1) method on
   // every object (whatever it's type) in the same group as the trigger.
   Parent::onEnterTrigger(%this,%trigger,%obj);

       %trans = nameToId("Door4").getTransform();
       %rot = getWord(%trans, 3)
          SPC getWord(%trans, 4)
          SPC getWord(%trans, 5)
          SPC getWord(%trans, 6);
        nameToId("Door4").setTransform("272.502 74.2818 204.473" SPC %rot ); //door open position

//Let's play a sound so the player hears the door open.
       alxPlay( "DoorOpen" );
}

and onLeaveTrigger add:

// This method is called whenever an object leaves the %trigger
   // area, the object is passed as %obj.  The default onLeaveTrigger
   // method (in the C++ code) invokes the ::onTrigger(%trigger,0) method on
   // every object (whatever it's type) in the same group as the trigger.
   Parent::onLeaveTrigger(%this,%trigger,%obj);
    %trans = nameToId("Door4").getTransform();
       %rot = getWord(%trans, 3)
          SPC getWord(%trans, 4)
          SPC getWord(%trans, 5)
          SPC getWord(%trans, 6);
        nameToId("Door4").setTransform("276.502 74.2818 204.473" SPC %rot ); //door closed position
        
//Let's play a sound so the player hears the door close.
       alxPlay( "DoorClose" );
}


Brian, thanks. I know of the problems with moving dif objects. They lose their collision properties while they are moving. (not to mention they move super super fast)
I've tried to make dts objects but haven't been able to get one to keep its texture. I'm going to attempt to remove the collison box off the glass and see if that works, if not, I'll just leave it out.
Thanks for the help guys. It is appreciated. :)