Game Development Community

dev|Pro Game Development Curriculum

A new Door class for Torque3D

by Richard Marrevee · 10/17/2014 (2:45 pm) · 8 comments

While I was testing/playing the soon to release demo of my game The Master's Eye, I got stuck in a door. I thought I had overcome these kind of problems by using triggers, but apparently not. Now The Master's Eye is a game in a medieval fantasy setting, so most of the doors are of the swinging kind. Only not this time, the player was trapped in a collision mesh of the open door and did not move in any direction. After analyzing the problem I decided that I needed a good working door object that lacked all these kind of problems. And preferably has all the necessary logic to respond to most of the actions you might want to perform on a door. Now, less then 2 weeks later, there it is: the new DoorClass object for Torque3D. And it is available to all of you and for free!! The DoorClass pack is released under the MIT license and contains all the source files to add this nifty class to the engine. And it is for all kind of doors: swinging, sliding, single and double doors.

So how does it work?

The Door class is a ShapeBase derived class, so there is a datablock called DoorData which holds the shapefile and some other stuff about the door and there is the Door object which represents the door in our game world.

There are however, a few demands for the door shape:
  1. it must contain an open and a close animation, named open and close,
  2. These animations must have triggers set on certain frames, to control the state of the door,
  3. A collision mesh for the closed door position, in case of a double door this must be just 1 single mesh,
  4. A collision mesh for the open door position, in case of a double door this will be 2 meshes,
  5. A collision mesh covering the whole area of the door animation, but simplified. In case of a swinging door this can be a low poly quarter of a cylinder. Also this mesh must be axis aligned to be certain of a correct doorblock check. You can, however, rotate the door in the world-editor, the blocked door check will calculate with it.
  6. The collision meshes must follow a naming rule.
Features:
  1. The datablock can hold sounds which will be played when opening/closing a door and when a player tries to open a locked door,
  2. The object can hold an ItemData that must be used to open the door. This ItemData will be passed to TS through callbacks,
  3. Depending on how you build the engine (this is explained in the installation guide which is included in the pack) the datablock or the object can hold messages for a locked or a blocked door situation and will be passed to script through callbacks. When the engine is build to have these messages be part of the object, you can give every single door in your game a different message, otherwise it is on a per datablock base.
  4. You can operate the door object without the need to know if it is locked, blocked, open or close, all is handled by the methods.
  5. The blocked door test can be enabled/disabled on an object base.
  6. onOpen, onClose, onLocked, onDoorblocked and an onLock callback give maximum control of the door.
The next video shows how easy it is adding a door to your mission with the world editor (as always the videos are best viewed in HD).



Now the next video shows the use of this door in a game.



Curious on how it looks in a real game? The following video shows the Door class in my game The Master's Eye in different situations.



How do I get this DoorClass pack?

You can download the zipped pack from my website here. As mentioned before it is for free, but if you find it useful and you are feeling generous, feel free to donate, it is much appreciated.

I hope you like it, thanks for reading.

Richard

About the author

Started programming in 1984 on an Oric, when time progressed switched to MSX, Amiga and finally the Windows PC with T3D. Now developing an epic fantasy game: The Master's Eye. Creator of the DoorClass pack and VolumetricFog pack @ richardsgamestudio.com


#1
10/17/2014 (5:16 pm)
Awesome idea! And thanks for contributing it open-source. I'll have to check this out soon...
#2
10/17/2014 (11:09 pm)
Cool stuff! Thanks for share!
#3
10/18/2014 (6:32 am)
Well done, Richard!
#4
10/18/2014 (9:03 am)
it is chic and necessary class, I'm still not completely try 3.6.1 version but eagerly jumping, waiting for 3.6.2. By the way is it possible to make some sort of lift with a choice of floor with help Klas door? my question may be silly, but just a thought out loud ...
#5
10/19/2014 (7:39 am)
Awesome work, thanks for sharing! Now that's a very useful resource!
#6
10/21/2014 (3:23 am)
Before I've had a chance to look at this - how do you handle Player's collision caching? Surely that would mean that if you opened a door near a Player, they wouldn't respond to the changed collision environment?

EDIT: game is looking great, by the way!
#7
10/21/2014 (2:26 pm)
@Daniel:
I ain't doing some fancy stuff here. When animating the door the triggers set in the animation will hide or show a collisionmesh using setMeshHidden... When you look at the next vid showing the sequence of the collision meshes in slomo, you can see that the new mesh is detected right away (it is a singleplayer game, don't know if that will make any difference). Best seen in HD.



Edit: When trying to open the door (I am using the keyboard), the method first checks to see if a players bounding box is within (overlapping, containing) the bounding box of the collision mesh that covers the area used by the animation. If true, than refuses to open the door, else show the animations collision mesh (which is detected right away as we can see in the video) so the player isn't able to move to a location where there will be a collision mesh for the opened or closed position of the door.
#8
10/22/2014 (12:00 pm)
This is definitely an interesting way to approach doors, I had a thread about it (http://www.garagegames.com/community/forums/viewthread/138950) and ways we could do doors.

Your way of blocking the animated areas works really well in your instance, I created my own door system which is very similar in many ways though a little more hands on. You technique of blocking the player from passing through or into the doors path during animation has inspired me to do some additional tests of my own. I still this this is a fundamental in Torque 3D that needs a bit more attention but its cool to see people problem solving it in different ways.