Game Development Community

dev|Pro Game Development Curriculum

Door Object

by Joshua Jewell · 11/21/2006 (4:49 pm) · 25 comments

Download Code File

In order to add Door functionality into your game perform the following tasks.

=============================================
Add the following files into the engine/game/ directory

stopWatch.h
stopWatch.cc
door.h
door.cc

Now add these files into your projects workspace and compile.
=============================================
Add the following directory into the starter.fps/data/shapes/ directory

door
=============================================
Add the following script file into the starter.fps/server/scripts/ directory

Door.cs

Then add this line of code in starter.fps/server/scripts/game.cs inside the onServerCreated function:

exec("./door.cs");
=============================================
In order to add the door into the mission you will need to edit the mission file with a text editor. Here is an example of how to add a door:

new Door()
{
position = "204.274 133.53 227.3";
rotation = "0 0 -1 90";
scale = "1 1 1";
dataBlock = "Door1";
};
=============================================

Notes

A door must be modeled a certain way in order for it to rotate properly. The main thing to note is that the door rotates around the transformation. Inside the zip file is an illustration of how the doors behavior will affects the dts shape.

Running into a door that stops because it is obstructed may produce a slight bouncy effect. This is due to the fact that the server and client do not transmit the transformation on each tick. This may be changed if serious de-synchronization occurs as a result.

I am not quite satisfied with the way a door detects that it is obstructed. Right now it checks a big box to see if any player enters it. In the future (Once I figure it out) I will have it so that the door only checks the area that it exists in.

The door's transformation cannot be changed while it is opening or closing. Once it is in a closed or open state it can be moved. The new transformation will be used when it starts to close/open again.

If I missed anything please bear with me as this is my first resource. I will try to fix any errors as quickly as possible as well as clear up any questions people may have.

*In order to make the door open and close call the script method toggle(). This method will have no effect if the door is not in a closed or open state. Here is an example of the script code:

%obj.toggle;

About the author

Recent Blogs

Page «Previous 1 2
#1
11/21/2006 (5:39 am)
Thanks Joshua!!
#2
11/22/2006 (7:25 am)
Thank you very much for sharing, nice first resource =)
#3
11/22/2006 (8:33 am)
I am glad that this resource is helpful to the community. It feels really good to finally give back something.

Thanks Paul!
#4
11/23/2006 (7:19 am)
cool!
#5
11/23/2006 (9:47 am)
Thanks Josh, I've been looking for other door resources to compare to the one I currently have in Ars Moriendi. I definitely want to have a door system similar to Resident Evil 4, and I think this will meld nicely with my current system.
#6
12/02/2006 (5:04 am)
This has got to be the best door resource I have found.
It just plain works, and works great!!

Thanks For This.
#7
12/03/2006 (9:11 am)
if you want to be able to add the door from the editor add the following to Door.cs
--------------------------------------------------------------------------------------------------------
function DoorData::create( %data )
{
	%obj = new Door()
	{
		dataBlock = %data;
		rotation = "0 0 -1 90";
		scale = "1 1 1";
	};

	return %obj;
}
#8
12/18/2006 (12:43 pm)
I must be the only person who got this error, but I had to change a piece of the engine code or else my game crashed:

[b]C H A N G E     T H I S:[/b]
void DoorData::unpackData(BitStream* stream)
{
   Parent::unpackData(stream);
   
   inverse = stream->readFlag();
   stream->read(&speed);
   stream->read(&maxRotation);
   stream->readInt(32);
   [b]stream->write(boundingBoxSide);[/b]
}

[b] T O :[/b]
void DoorData::unpackData(BitStream* stream)
{
   Parent::unpackData(stream);
   
   inverse = stream->readFlag();
   stream->read(&speed);
   stream->read(&maxRotation);
   stream->readInt(32);
   [b]stream->read(&boundingBoxSide);[/b]
}

I was under the assumption that you NEVER performed writing during an unpackData routine. Ah well, the change worked for me. Great resource! I'm going to try to make some additions to the rotation to allow for more control over opening and closing, like Ghost Recond, Ravenshield, and Resident Evil 4.
#9
12/18/2006 (1:46 pm)
Good find, thank you for the correction and sorry for the mistake. I think using copy and paste too much was the culprit.

I have only had a little time to research collisions more because of finals. I have however gotten close to having the door stop movement when you obstruct it and not just a box around it. Hopefully once everything settles I will be able to add that as well as more solid networking.
#10
04/05/2007 (9:11 am)
when compiling TGEA whit this addon i get the following error:
1>c:\development\torqueadvanced\sdk\engine\game\door.cc(8) : fatal error C1083: Cannot open include file: 'dgl/dgl.h': No such file or directory
#11
04/05/2007 (1:05 pm)
@Mikael Pettersson
This resource is for TGE (OpenGL), but rendering code from TGEA has been rewritten. TGEA has it's own rendering commands that will translated into Direct3D and later also OpenGL. Don't use Direct3D or OpenGL directly in TGEA.
Take a look in the header files in TorqueAdvanced\SDK\engine\gfx of your SDK. Specialy at primBuilder.h.

Martin
#12
04/05/2007 (3:11 pm)
ok so i just comment out that include then? Im not realy a coder... im a 3D artist so i barely know coding 101...
#13
05/24/2007 (10:12 am)
Works great, one issue, I have the door doing horizontal slide, server side player works fine but client sees it swing.
#14
06/17/2007 (8:44 pm)
Just wanted to let you know, this resource is excellent, thank you so much for this. Until this resource i was doing doors with animated DTS objects, this eliminates that headaches. This resource works perfectly (using the minor change micheal perry mentioned) on TGE 1.3 and1.4.2.

Cheers mate rating of 5 for this one.
#15
07/01/2007 (9:08 am)
@Howard

Sorry for not responding sooner I have not checked this Thread in quite a while. Although I do not have the time to spend to tackle this issue completely I will try to provide some useful information.

The door decides how to open based off of the type flag. By default the door will swing/rotate. However the datablock should over write this. If the server is seeing the door slide horizontally but the client is not then it sounds like the datablock is not being sent to the client properly. The method void DoorData::unpackData(BitStream* stream) does the work of taking the datablock information and overwriting the default. This would be the first place I would look in trouble shooting this issue.

Again I apologize for not being able to track this error down myself. Hopefully this information helps.
#16
07/10/2007 (6:01 am)
@Howard

The problem might be because in DoorData::unpackData

stream->readInt(32);

is not assigning the value to DoorData::type. I have not tested it yet, but I think that might be the reason.
#17
07/13/2007 (7:04 am)
Please forgive my ignorance. But can someone please give an example of how to connect this to a key press. I added %this.toggle(); to my player.cs onCollision() but not dice. Please help! Thanks!

I'm a big dummy but I got it worked out in the forum's with Stephen's help here's the link.

http://garagegames.com/mg/forums/result.thread.php?qt=64685
#18
07/15/2007 (10:48 am)
Thanks for this great resource!

Seems like that type issue can be fixed by changing type to a float instead of int.

door.h:

bool inverse;
   F32 speed;
   [b]F32 type;[/b]
   F32 maxRotation;
   F32 boundingBoxSide;

door.cc:

addField("inverse",			TypeBool, Offset(inverse, DoorData));
   addField("speed",			TypeF32, Offset(speed, DoorData));
   addField("maxRotation",		TypeF32, Offset(maxRotation, DoorData));
   [b]addField("type",			TypeF32, Offset(type, DoorData));[/b]
   addField("boundingBoxSide",		TypeF32, Offset(boundingBoxSide, DoorData));

stream->writeFlag(inverse);
   stream->write(speed);
   stream->write(maxRotation);
   [b]stream->write(type);[/b]
   stream->write(boundingBoxSide);

inverse = stream->readFlag();
   stream->read(&speed);
   stream->read(&maxRotation);
   [b]stream->read(&type);[/b]
   stream->read(&boundingBoxSide);
#19
07/25/2007 (12:08 am)
Hi! Is this code working on TGE 1.5.2? I have done all the instructions but i cant make the door data work. (Unable to instantiate non-conobject class DoorData.) Pls help. tnx
#20
07/29/2007 (7:54 pm)
Yes, I got it working just now on 1.5.2. Maybe you forgot to add some of the files to the project? Did you recompile?
Page «Previous 1 2