Just wanted to update that I did get the door working with the collisions updating properly. I'll post my script but there's other door scripts out there that might be better for what you want.
I split the door from the frame and rotated the entire object and it works fine. Right now it opens when you walk into a box and closes slower when you leave the box. It can be set to work any way, such as read your distance and open more as you approach or stay open or whatever. The frame is just another object put there, I wont' post the .OPR for it cause it's nothing to do with it.
Door_Solo.OPR
OPRP
LoadObject Door_Solo.FBX
EditObject Hinge
ObjectName Hinge
ObjectMaxDepth 40
EditObject Door
ObjectName Door
ObjectParent Hinge
ObjectMaxDepth 200
EditObject Fittings
ObjectName Fittings
ObjectParent Door
ObjectMaxDepth 20
EditObject Knobs
ObjectName Knobs
ObjectParent Fittings
ObjectMaxDepth 80
EditObject Latch
ObjectName Latch
ObjectParent Fittings
ObjectMaxDepth 20
AddCollision Box
CollisionType Box
CollisionBoxSize 16.5 44.5 1.6
CollisionCenter -8.2 22.53 1.25
CollisionTransformIndependently 0
CollisionMass 0
CollisionMassOffset 0.000000 0.000000 0.000000
CollisionFriction 0.1
CollisionBouncyness 0
CollisionBounceVelocity 0.1
CollisionGravityEnabled 0
Keep in mind all parameters are to my object's scale.
Door.gsl
float spin = 0;
float maxopen = -85;
Vector vspin;
bool open = false;
Matrix startingMatrix;
int x;
String VictoryController = "cheesebit_global";
void Initialize( Object@ object)
{
Object@ door = GetGameManager().GetWorld().GetObject("Door_Solo");
startingMatrix = door.GetCurMatrix();
vspin.z = 0;
vspin.y = 0;
vspin.x = 0;
//~ Vector rotation = object.GetMesh("Hinge").GetRotationEuler();
//~ object.UpdateCollisionObjectPositions();
//~ print(rotation);
}
bool HandleEvent( Object@ object, const String& in event, GameEventParams@ params)
{
Object@ victoryobject = GetGameManager().GetWorld().GetObject("cheesebit_global"); //get handle to victory state
bool victory = victoryobject.GetControllerSettingBool("WON");
if(victory == true)
{
if(event == "EnterProximity")
{
print("IN");
}
if(event == "Input")
{
open = true;
}
else
{
open = false;
}
return true;
}
else
{
GetGameManager().ShowTextPlain("YOU HAVEN'T CLEARED THE ROOM!", 2);
return false;
}
}
void DynamicsAdvance( Object@ object, float seconds)
{
Object@ door = GetGameManager().GetWorld().GetObject("Door_Solo");
door.GetCurMatrix() = startingMatrix;
door.GetCurMatrix().Rotate( vspin);
door.UpdateCollisionObjectPositions();
if(open == true)
{
if(vspin.x<=maxopen)
{
vspin.x = maxopen;
}
else
{
vspin.x -= 0.5;
}
}
else
{
if(vspin.x>= 0)
{
vspin.x=0;
}
else
{
vspin.x += 0.1;
}
}
}
I also did a fan with basic rotation.
Ceiling_Fan.OPR
OPRP
LoadObject CeilingFan_Blades.FBX
ControllerType Scripted
ControllerSetting ScriptFile FanSpin.gsl
ControllerInputCenter -10 2.5 0
ControllerInputBoxSize 3 5 10
AddCollision Collision
CollisionType UseRenderObject
CollisionFriction 999999
CollisionBouncyness 0
CollisionBounceVelocity 0.1
CollisionGravityEnabled 1
FanSpin.gsl
Vector vspin;
Matrix startingMatrix;
//
void Initialize( Object@ object)
{
vspin.y=0;
vspin.z=0;
startingMatrix = object.GetCurMatrix();
}
//
bool HandleEvent( Object@ object, const String& in event, GameEventParams@ params)
{
return true;
}
//
void DynamicsAdvance( Object@ object, float seconds)
{
object.GetCurMatrix() = startingMatrix;
object.GetCurMatrix().Rotate( vspin);
object.UpdateCollisionObjectPositions();
vspin.x += 0.1;
}
When standing on the blades (mine are giant) you have to walk to stay on it, you don't stick or spin with it. I haven't tackled this yet.
Also: That's only one way to spin the object, and it's actually more suited for a situation where you'd want to be able to only rotate the blades to a particular angle and stop or go the other way (more for a door). If you just want a simple spin on your object, the following script will suffice. It's gonna spin really fast at 10 degrees away from its current rotation, calculated per tick.
void DynamicsAdvance( Object@ object, float seconds)
{
object.GetCurMatrix().Rotate( 10,0,0);
object.UpdateCollisionObjectPositions();
}