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
#2
10/24/2005 (11:04 am)
no, if you touch it while it's closing, it starts to play the animation backwards. Plus it won't try to close if the player is within a certain range.
#3
10/24/2005 (1:59 pm)
I got it into the game and got it animated or open the door. But I cant go through it. sniff. :) Is there a wa to go through
#4
Are you getting inside the door? or not even making it that far?
10/24/2005 (2:00 pm)
Well.. i said i made the door specific for my game and that you can't go thru :) that's due to the collision mesh. I'll update the archive with a DTS just like it that you can go thru.Are you getting inside the door? or not even making it that far?
#5
10/24/2005 (2:31 pm)
Ok, i updated the door, it's got a new file name, went from door.dts to door2.dts, so you might want to reflect that in your CS file.
#6
Might come in handy for my distant future space horror RPG (distant future as in my time constraints :))
10/24/2005 (6:53 pm)
Nice!Might come in handy for my distant future space horror RPG (distant future as in my time constraints :))
#7
10/25/2005 (5:19 am)
Er.. what happens if you shoot the door?
#8
10/25/2005 (5:36 am)
Nothing. Collisions aren't called for projectile hits are they?
#9
That will make the door open only if a player, vehicle or anything under shapebase hits it.
(Projectiles are under GameBase)
EDIT: weird, just tried this with starter.racing and I can't go thru the door, (it opens for me tho!) I scaled it bigger and sunk it into the ground and still no go :\
EDIT2: This is with current TGE 1.4 beta
10/25/2005 (7:41 am)
function door::onCollision(%this,%door,%col){
if (%col.getType() & $TypeMasks::ShapeBaseObjectType) {
if (!%door.open) {
%door.open=true;
%door.setthreaddir(0,"true");
%door.playthread(0,"open");
%this.schedule(4000, close, %door,%col);
}
}
}That will make the door open only if a player, vehicle or anything under shapebase hits it.
(Projectiles are under GameBase)
EDIT: weird, just tried this with starter.racing and I can't go thru the door, (it opens for me tho!) I scaled it bigger and sunk it into the ground and still no go :\
EDIT2: This is with current TGE 1.4 beta
#10
10/25/2005 (7:06 pm)
Not to rain on your parade but in Advanced 3d game programming all in one there is a whole chapter on sliding and swinging doors. Since I haven't read that part yet I can't say if this is better or worse way of doing it.
#11
10/26/2005 (3:07 am)
ah, that's cool they have it in there. But stil that book is $50 bucks.
#12
10/27/2005 (10:53 am)
@Ramen - Nice work. I'm more interested in knowing how you made the shape and baked in the sequences. Any chance you would share that? I know there are resources, but it's always nice to have a working example.
#13
10/27/2005 (10:55 am)
Sequences are stored in the dts by selecting export whole shape. Is that what you mean?
#14
10/27/2005 (11:04 am)
Yes. That's what I mean. I'd be interested to know the necessary process to rig and animate the door. I'm a programmer by trade so all of this modeling business is foreign to me. My modeler is MIA at the moment so I'm trudging along without him. Besides, the more I know, the less I sound like a raging idiot when I talk to him.
#15
10/27/2005 (11:23 am)
Good Point Ramen and thanks for sharing the door code with us!
#16
10/27/2005 (12:38 pm)
The door only has 1 bone, which moves the door itself. parrented to that bone is a collision mesh about the size of the door. In addition to that collision mesh, i have some other collision meshes for the frame of the door. That's the only real magic to it. I use Lightwave 3d for my modeling so any specifics beyond that would pertain directly to lightwave. But the process is similiar for other programs.
#17
10/28/2005 (10:18 am)
I tried the same thing before, but discovered that TGE doesn't move collision meshes when playing an animation. I tried your resource and I could not walk through the door. Has anyone been able to walk through the door?
#18
10/28/2005 (10:22 am)
hmm that's interesting. i haven't made many changes to the engine. but this resource does infact work. Let me test on a clean build and provide any code changes it takes.
#19
10/28/2005 (10:33 am)
Well i added it into a clean build and it works like it should. i tired a few differnet ways of adding it into the scene and it would open and i could pass thru. perhaps the character you're using is too big to fit? 

Torque Owner Neil M.
Default Studio Name