Animated DTS Doors
by Cinder Games · 10/24/2005 (8:01 am) · 30 comments
Download Code File
Ever wanted to have a simple door that slides open and lets your thru? This small resource will show you how to go about doing it.
Make sure you place this script into /server/scripts
and the door2.dts file will need to go into ~data/shapes/areas/door2.dts or you will need to simply change this script file to point to it's new location.
There's the code. But i think it's more important to look at how i made the door itself. The door features about 4 convex collision meshes, 3 for the outside of the door, and 1 for the actual door itself. The door is animated, has 1 bone that move the door itself. Parented to the bone, is a collision mesh for the door. So moving the bone, moves the mesh. I can explain this in more detail, but i'll simply provide my dts door to be examined.
The door is now fully functional. I've updated the DTS so you can walk thru it like you should.
I haven't tried to make it work for swinging type doors yet, but i'll see what it takes for that and update the code with that. I should mention that texture included.. i can't really remember where i found it.. so don't use it in anything you make.
Ever wanted to have a simple door that slides open and lets your thru? This small resource will show you how to go about doing it.
Make sure you place this script into /server/scripts
and the door2.dts file will need to go into ~data/shapes/areas/door2.dts or you will need to simply change this script file to point to it's new location.
//Door.cs
//writen by Ramen Sama
datablock StaticShapeData(door){
category = "Doors";
//Points to the DTS object change this for your project
shapeFile = "~/data/shapes/areas/door2.dts";
position = "0 0 0";
Scale="1 1 1";
emap = false;
receiveSunLight = "1";
};
//Called when you touch the door
function door::onCollision(%this,%door,%col){
if (!%door.open){
%door.open=true;
%door.setthreaddir(0,"true");
%door.playthread(0,"open");
%this.schedule(4000, close, %door,%col);
}
}
function door::close(%this,%door,%col){
//does a distance check between the door and what hit it last
//I have it set for 2... but you can use whatever you like
%dist=VectorDist(%col.getposition(), %door.getposition());
if (%dist > 2){
%door.setthreaddir(0,"false");
%door.open=false;
}
else
//if the player is too close, just go ahead and start the timer again
%this.schedule(4000, close, %door,%col);
}There's the code. But i think it's more important to look at how i made the door itself. The door features about 4 convex collision meshes, 3 for the outside of the door, and 1 for the actual door itself. The door is animated, has 1 bone that move the door itself. Parented to the bone, is a collision mesh for the door. So moving the bone, moves the mesh. I can explain this in more detail, but i'll simply provide my dts door to be examined.
The door is now fully functional. I've updated the DTS so you can walk thru it like you should.
I haven't tried to make it work for swinging type doors yet, but i'll see what it takes for that and update the code with that. I should mention that texture included.. i can't really remember where i found it.. so don't use it in anything you make.
About the author
#22
Is there a performance benefit to having doors for blocking inside/outside views? For example, if you were outside with a door closed to an interior building, would the contents inside be culled from view (portal is not viewable?). If not, would it be possible?
john
10/31/2005 (3:25 pm)
Question:Is there a performance benefit to having doors for blocking inside/outside views? For example, if you were outside with a door closed to an interior building, would the contents inside be culled from view (portal is not viewable?). If not, would it be possible?
john
#23
11/01/2005 (5:18 am)
I don't believe portals see DTS shapes at all. They are just part of the DIF so no having a door in the doorway wouldn't make a difference.
#24
11/01/2005 (3:21 pm)
Anyone else had any issue with not being able to pass thru?
#25
11/10/2005 (3:47 pm)
@Ramen: I have had that problem when my player's bounding box was too large, but otherwise no =)
#26
12/01/2005 (10:00 am)
Ive had issues, when i get near the door, it doesnt open at all! why is that?
#27
12/01/2005 (3:48 pm)
well, first thing i can think of... is did you include the door.cs to your project? 2nd thing, with my current code, you must touch it to have it open.
#28
I had created a new folder in ~/data/shapes/doors and had put doors2.dts and bcmetal06a.jpg in that folder.
Then I put doors.cs into ~/server/scripts
But the doors folder was showing up in the static shapes instead of shapes. I could place a door but it would not open. Time to look at the script and of course its nicely commented what to do. I had to change this line:
//Points to the DTS object change this for your project
shapeFile = "~/data/shapes/areas/door2.dts";
to the doors folder in my project:
//Points to the DTS object change this for your project
shapeFile = "~/data/shapes/doors/door2.dts";
Then, of course, it works perfectly !
04/08/2006 (12:45 pm)
I had a lot of problems getting this do work ... until I read the script: doh!I had created a new folder in ~/data/shapes/doors and had put doors2.dts and bcmetal06a.jpg in that folder.
Then I put doors.cs into ~/server/scripts
But the doors folder was showing up in the static shapes instead of shapes. I could place a door but it would not open. Time to look at the script and of course its nicely commented what to do. I had to change this line:
//Points to the DTS object change this for your project
shapeFile = "~/data/shapes/areas/door2.dts";
to the doors folder in my project:
//Points to the DTS object change this for your project
shapeFile = "~/data/shapes/doors/door2.dts";
Then, of course, it works perfectly !
#29
04/08/2006 (2:26 pm)
Glad it worked out for ya. I went ahead and explained that a little more in the resource. Thanks fo the feedback.
#30
for Rotational Doors you need collision mesh for all time.
for having collision mesh during door moves , must rotate it using schedule.
schedule time define door open/close speed.
sample code:
function Doors::Open(%door)
{
if (%door.opened) return;
//%door.playthread(0,"open"); // old method that not include collision
SoundPlayer::sfxplay(SFXOpenDoor);
RotateDoor(%door);
}
function RotateDoor(%door)
{
cancel(%door.openSCH);
%rotation=getwords(%door.gettransform(),3,7);
%positon=%door.getposition();
%factorZ=getword(%rotation,2);
%gFactor=getword(%rotation,3);
%gFactor=%factorZ*%gFactor;
%directioFactors="0 0 1";
if (!%door.registerOR) {
%door.orginalRotation=%gFactor;
%door.registerOR=1;
}
if (%door.openAmount>0) { // door open to positive direction
%directionAmount=1* $GamePlay::DoorOpenAmount;
if (%gFactor>%door.orginalRotation+%door.openAmount) {
%door.opened=1;
return;
}
}
else{
%directionAmount=-1 * $GamePlay::DoorOpenAmount;
if (%gFactor<%door.orginalRotation-%door.openAmount) {
%door.opened=1;
return;
}
}
%door.settransform(%positon SPC %directioFactors SPC %gFactor+%directionAmount);
%door.openSCH=schedule(1,%door,RotateDoor,%door);
}
09/11/2008 (3:10 am)
in tgea 1.7 collision mesh don't work after move.for Rotational Doors you need collision mesh for all time.
for having collision mesh during door moves , must rotate it using schedule.
schedule time define door open/close speed.
sample code:
function Doors::Open(%door)
{
if (%door.opened) return;
//%door.playthread(0,"open"); // old method that not include collision
SoundPlayer::sfxplay(SFXOpenDoor);
RotateDoor(%door);
}
function RotateDoor(%door)
{
cancel(%door.openSCH);
%rotation=getwords(%door.gettransform(),3,7);
%positon=%door.getposition();
%factorZ=getword(%rotation,2);
%gFactor=getword(%rotation,3);
%gFactor=%factorZ*%gFactor;
%directioFactors="0 0 1";
if (!%door.registerOR) {
%door.orginalRotation=%gFactor;
%door.registerOR=1;
}
if (%door.openAmount>0) { // door open to positive direction
%directionAmount=1* $GamePlay::DoorOpenAmount;
if (%gFactor>%door.orginalRotation+%door.openAmount) {
%door.opened=1;
return;
}
}
else{
%directionAmount=-1 * $GamePlay::DoorOpenAmount;
if (%gFactor<%door.orginalRotation-%door.openAmount) {
%door.opened=1;
return;
}
}
%door.settransform(%positon SPC %directioFactors SPC %gFactor+%directionAmount);
%door.openSCH=schedule(1,%door,RotateDoor,%door);
}

Torque Owner Shon Gale
http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=4004
We at ATOMIX use this one which we recently modded to the new book example. 3D Game Programming All in One Advanced by Kenneth Finney.