Game Development Community

dev|Pro Game Development Curriculum

Door Object Part 2

by Jeff Loveless · 10/18/2007 (2:06 pm) · 7 comments

Download Code File

Torque Version: 1.5.2

This is a modification to Joshua Jewell's door resource, which is found here. To install this, extract the files from the given .rar file, then follow Mr. Jewell's installation instructions, which I have quoted here:
Quote:
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");

The changes I have made are as follows:

- the door can now be toggled mid-swing (while it is still opening or closing).

- I've added console functions setToOpen() and setToClosed() to set the door to open or closed without animation (good for initializing the door). The initial door state can be set in the .cs file if you implement the onAdd() function.

- any transform (rotation, translation) can be applied to the door and it will still open and close just fine; all transforms that handle the door opening/closing are now done in object coordinates instead of in world coordinates (in english: you can tilt the door, say 45 degrees, and it will rotate or slide in a rotated path). As such, I disabled the check in setTransform() which prevented the door from being transformed while it was opening or closing.

- boundingBoxSide can now be automatically calculated optionally to something reasonably appropriate-just set boundingBoxSide to -1 in the data block to do so. I also set up some code to handle the bounding box when the door is rescaled.

- inversion works a little differently now. I made it so inversion actually reverses the motion of the door rather than simply changing the state the door starts out in.

- moveDist was being ignored in the datablock. This is no longer the case.

- fixed a sync bug between the server and client.

- other minor changes, some are minor bugs fixes and some are spelling fixes or other cosmetic alterations. :)

#1
10/22/2007 (6:28 am)
Great resource, but there is some way to make the door pushs the player out of its way if they collid ?
#2
10/24/2007 (3:02 pm)
Diego: you would have to do some kind of collision detection for the door while it is in motion. For a sliding door, you could probably just use an ExtrudedPolyList (like Players use) (faking the appropriate displacement and velocity vectors) and, once contact was detected, give the player (or whatever object you had in mind) an appropriate little bit of impulse.

If you are talking about pushing someone with a *rotating* door, then that's a much different story. If that is what you need, you've got all kinds of "fun" ahead of you... 8|
#3
11/07/2007 (7:18 pm)
Excellent addition to the resource! I am curious if you tried to have the door use its actual shape for collisions instead of a bounding box. I remember that being a nightmare for me! Which is why It never got accomplished. Anyway just wanted to pop on and say great work. You added some much needed improvements :-p
#4
12/12/2007 (2:38 pm)
Thank you for your comments, Joshua.

As for collisions, the only shape I used when I messed around with collisions with a door was its bounding box.

Sorry it took so long for a non-answer 8^)

You might try checking out the polysoup stuff. It might lead you closer to what you are looking for.
#5
12/28/2007 (11:12 am)
@Jeff or Joshua - Would you be able to provide some instructions for adding a 'movemap.bindcmd' to operate the door?
I know this was asked in Joshua's initial resource, unfortunately I couldn't make sense of the guys solution. I get lost with the 'function serverCmdinteract(%client)' stuff.
I was hoping to use the same key to open and close the door. (I've avoided using other door resources b/c they all have an auto close feature.)
It would be greatly appreciated by non-coder artists like me. :)
#6
02/05/2008 (5:01 pm)
Hey Kerry I looked for a way to send you a "private message" but didn't see anything.

One thing you can do is this
GlobalActionMap.bind( keyboard, "e", toggleDoor );

function toggleDoor( %val )
{
    if ( %val  )
    {
        $DoorObject.toggle();
    }
}

This of course will only work if you have reference a specific door. I did something similar a long time ago when I was working on a FPS. What I did was bind the e key to a ray casting. The ray casting would then check to see what objects were returned, if it found a door object it would then toggle it.

The thing you have to watch out for with ray casting is providing the correct object id. (ie StaticObject, etc)

Feel free to message me any time here is my info:
AIM = joshjewell29
Yahoo = joshjewell29

I will have a much easier time helping you out through a messenger since the comment turn around time on resources can be in the months!
#7
09/27/2008 (7:17 am)
The rotation works great but my player can't enter or leave the doorway. The door collision box prevents passing. Any way around this ?