I see. Indeed, this whole multi-file hack is kind of messy.
Okay now I have a question. First, I shall post Chris' code here.
Code: Select all
/*
Chris '06 Hinge Door concepting
Swings from both sides, avelocity overshot issue resolved using .ltime.
RSTATE variable:
0 = idle/closed
1 = active
Due to some origin issues to be able to have the door swing in the correct
fashion depending on where the player hits it you will have to use the
setpointdoor float as a key in the func_door_rotating entity in the map editor.
Their names correspond to when looking down from on top of the door (bird's eye view):
Their angle, if the door is the long way from left to right it is HORIZONTAL. If it is
long from top to bottom it is VERTICAL. The next bit corresponds to which side of the door
has the origin brush which decides from where it will swing from. If the origin brush is
on the left then it is LEFT_HINGE. And if it is on the right it is RIGHT_HINGE. In terms
of VERTICAL doors the LEFT_HINGE would be on the lowest end of the door if looking at it
from the top, and the RIGHT_HINGE would be the top of the door if looking at it from the top
view.
*/
float HORIZONTAL_LEFT_HINGE = 0;
float HORIZONTAL_RIGHT_HINGE = 1;
float VERTICAL_LEFT_HINGE = 2;
float VERTICAL_RIGHT_HINGE = 3;
.float RSTATE, reverse, setpointdoor;
void() thc_door_open;
float(entity targ) infrontofdoor =
{
local vector vec;
local float dot;
makevectors (self.angles);
vec = normalize (targ.origin - self.origin);
if (self.setpointdoor == HORIZONTAL_LEFT_HINGE)
dot = vec * v_right;
if (self.setpointdoor == HORIZONTAL_RIGHT_HINGE)
{
dot = vec * v_right;
dot = dot * -1;
}
if (self.setpointdoor == VERTICAL_LEFT_HINGE)
dot = vec * v_forward;
if (self.setpointdoor == VERTICAL_RIGHT_HINGE)
{
dot = vec * v_forward;
dot = dot * -1;
}
if ( dot > 0.3)
{
return TRUE;
}
return FALSE;
};
void() func_door_rotating =
{
if (self.sounds == 0)//no sound
{
precache_sound ("misc/null.wav");
precache_sound ("misc/null.wav");
self.noise1 = "misc/null.wav";
self.noise2 = "misc/null.wav";
}
if (self.sounds == 1)//generic
{
precache_sound ("thcdoor/open1.wav");
precache_sound ("thcdoor/close1.wav");
self.noise1 = "thcdoor/open1.wav";
self.noise2 = "thcdoor/close1.wav";
}
if (self.sounds == 2)//metal squeaky gate
{
precache_sound ("thcdoor/open2.wav");
precache_sound ("thcdoor/close2.wav");
self.noise1 = "thcdoor/open2.wav";
self.noise2 = "thcdoor/close2.wav";
}
if (self.sounds == 3)//heavy metal
{
precache_sound ("thcdoor/open3.wav");
precache_sound ("thcdoor/close3.wav");
self.noise1 = "thcdoor/open3.wav";
self.noise2 = "thcdoor/close3.wav";
}
setmodel (self, self.model);
self.takedamage = DAMAGE_NO;
self.solid = SOLID_BSP;
self.movetype = MOVETYPE_PUSH;
self.RSTATE = 0;
if (!self.targetname)
self.touch = thc_door_open;
self.nextthink = self.ltime + 9999999999999999999;
self.think = thc_door_open;
if (!self.wait)
self.wait = 0.1;
if (self.targetname)
self.use = thc_door_open;
if (!self.setpointdoor)
self.setpointdoor = 0;
self.avelocity = '0 0 0';
};
void() thc_door_closed =
{
self.avelocity = '0 0 0';
self.RSTATE = 0;
self.nextthink = self.ltime + 9999999999999999999;
sound (self, CHAN_VOICE, self.noise1, 1, ATTN_IDLE);
self.touch = thc_door_open;
};
void() thc_door_closing =
{
self.nextthink = self.ltime + 1;
self.think = thc_door_closed;
if (!self.reverse)
self.avelocity = '0 -80 0';
else
self.avelocity = '0 80 0';
sound (self, CHAN_VOICE, self.noise2, 1, ATTN_IDLE);
};
void() thc_door_opened =
{
if (!self.targetname)
{
self.avelocity = '0 0 0';
self.nextthink = self.ltime + 2;
self.think = thc_door_closing;
}
};
void() thc_door_opening =
{
self.nextthink = self.ltime + 1;
self.think = thc_door_opened;
if (!self.reverse)
self.avelocity = '0 80 0';
else
self.avelocity = '0 -80 0';
sound (self, CHAN_VOICE, self.noise2, 1, ATTN_IDLE);
};
void() thc_door_open =
{
self.avelocity = '0 0 0';
self.touch = SUB_Null;
if (!infrontofdoor(other))
self.reverse = 1;
if (infrontofdoor(other))
self.reverse = 0;
if (self.RSTATE == 0)
{
self.RSTATE = 1;
thc_door_opening ();
sound (self, CHAN_BODY, self.noise1, 1, ATTN_IDLE);
}
};
To get around WC's habit of stripping the "origin" key from my brushes, I would put this in the QC before any function...
... and modify the function infrontofdoor, specifically the line that says...
Code: Select all
vec = normalize (targ.origin - self.origin);
to
Code: Select all
vec = normalize (targ.origin - self.rotating_door_origin);
... so that I can put a key called rotating_door_origin in Worldcraft.
It's still not working. What am I doing wrong?