Game Development Community

Door resources in the works.. but need help.

by Steve Kilcollins · in Torque Game Engine · 07/10/2006 (8:43 pm) · 24 replies

I needed doors (mainly sliding doors) for what I'm doing so I've created a sliding door object (c++ code) which will slide the door in 14 different directions. (Up, down, left, right, forward, backward, (and the diagonal directions) left up, left down, right up, right down, forward up, forward down, backward up and backward down). The door will move in the direction specified for a number of units in a certain number of ticks. Will also close either manually or by a Holdopen timer. Collisions move, no special modelling tricks, interpolated and network ready.


My problem:
I'm trying to create a rotating door C++ object. I got it to rotate but it was rotating at the center of the object. So I added a hingeNode. I got the hingeNode to rotate by using the animate() function. But I discovered that the collision, and bounding box doesn't move.

What I want to do it rotate around the hingeNode. But I'm not sure which transform to use and just how to do it.

The RotatingDoorShape is derived from Shapebase

Here's what I have for the animate() function
RotatingDoorShape::onNewDatablock()
{
    ....
	hingeNode = getDataBlock()->hingeNode;
	mShapeInstance->setNodeAnimationState(hingeNode,TSShapeInstance::MaskNodeHandsOff);
}

RotatingDoorShape::openDoor()
{
      ...

	hingeMat = &mShapeInstance->mNodeTransforms[hingeNode];
	hingePos = getDataBlock()->shape->defaultTranslations[hingeNode];
	m_velocity = mDegToRad((F32)m_maxOpenAngle) / ((F32)m_dooropentimer / (F32)TickMs);

     ...
}

RotatingDoorShape::processTick
{

               	   currentRotation += (m_velocity * (F32(TickMs) / 1000.0f));
	   hingeMat->set(EulerF(0,0,currentRotation),hingePos);

	   mShapeInstance->setDirty(TSShapeInstance::TransformDirty);
	   mShapeInstance->animate();


}
Now getting rid of the animate() and trying to actually rotate the door, here's what I have so far..

RotatingDoorShape::openDoor()
{
      ...

	hingeMat = &mShapeInstance->mNodeTransforms[hingeNode];
	m_velocity = mDegToRad((F32)m_maxOpenAngle) / ((F32)m_dooropentimer / (F32)TickMs);

     ...
}


RotatingDoorShape::processTick
{

               	   currentRotation = (m_velocity * (F32(TickMs) / 1000.0f));
	   hingeMat->set(EulerF(0,0,currentRotation));

	   m_originalPosition = mObjToWorld;


 <    here's where I need the help,  what do I do next?  >

}

I've been struggling with this for a week and as soon as i can get this solved, then I can release both the sliding and rotating doors as a resource.
Page«First 1 2 Next»
#21
07/23/2006 (9:40 pm)
I could really use this code, I'll be watching for your resource.
#22
07/23/2006 (11:05 pm)
Rubes.. yeah.. I remember seeing something like that too. probably be able to modify it. At the moment, on the rotation its working when its just the Z axis.. but the X, Y is off a little bit. so have to figure that part out first.
#23
07/29/2006 (6:00 pm)
I have collisions working. :) I kind of followed how the player shape did it. So when the door moves, it checks to see if it has hit anything. When it does, it sends an onCollision to the script and it will be up to the script on how it wants to handle it.

The script can ignore the collision, or check to see what type it hit, and depending on the type you can do whatever you want. If it has hit a PlayerObjectType, it can push the object back (or forward).. if its a VehicleObjectType can pauseDoor() and schedule a continueDoor() a few seconds later,, in which case it will check for collision again and send an onCollision again.

The types it checks for are: StaticShapeObjectType, VehicleObjectType, PlayerObjectType, StaticTSObjectType, TriggerObjectType and ItemObjectType.

The number of types might be overkill, but I figured put them in ... never know what a person may use them for. A player could put a grenade at the foot of the door and when the door opens, the grenade goes off.

I have left a couple of little things to do:
get the position and direction the door hits the object and pass that on the onCollision callback
add collision to my sliding door

I'm begining to think about combining my sliding door shape and rotating door shape to just a doorshape.
#24
08/08/2006 (11:07 am)
Got it all working! When the door collides with an object, the door will execute a script onCollision call with the following parms: the object that was collided with, tells you if the door is facing the object, is the object facing the door, the distance between the 2 objects, the relative bearing of the door to the object, and the relative bearing of the object to the door, the vector the door is moving and the distance the door moved.

I'm just writing a basic script to push the player when the door has collided with it. Its not going to be anything fancy, just an example. Will leave anything more complecated to the scripter's needs.

I'm also thinking of having a DoorController object. This object would control multiple part doors(3 doors that make up a door). For example: one that slides up, one that slides left, and one that slides right. With the Controller, instead of doing 3 open calls from script for each door (doorThatSlidesUp.open(), doorThatSlidesLeft.open(), doorThatSlidesRight.open()) you would just do one call to Controller.open();

Collision with the controller: I'm thinking of giving the scripter 3 options; A) return a onCollision for the individual door part that collided (on onCollision for the controller), B) return the onCollision for the controller only (no oncollision for the individual doors BUT the onCollision for the controller would specify which section of door did the colliding), and C) return onCollision for each individual door AND the controller.
Page«First 1 2 Next»