But I notice that when the player moves up stairs, the flashlight bumps up and down really hard, like as if it's not keeping up with the player's movement.
Is there a way to interpolate the flashlight's position just like how the player's view is interpolated as he moves up and down?
Code: Select all
// flashlight code
// player flashlight state
.float flashlight_state;
.entity flashlight;
void() flashlight_think =
{
if (self.owner.health > 0)
{
//setorigin(self, self.owner.origin + (self.owner.view_ofs - '0 0 16'));
makevectors (self.owner.v_angle);
traceline (self.owner.origin, (self.owner.origin + (v_forward * 32)), FALSE, self);
setorigin(self, trace_endpos + (v_forward * -16) + (self.owner.view_ofs - '0 0 8'));
self.angles = self.owner.v_angle;
self.angles_x = self.angles_x * -1;
self.nextthink = time;
}
};
void() player_flashlight =
{
local entity newflashlight;
newflashlight = spawn();
newflashlight.pflags = PFLAGS_FULLDYNAMIC;
newflashlight.light_lev = 1024;
newflashlight.color = '2 2 2';
newflashlight.skin = 200;
newflashlight.owner = self;
self.flashlight = newflashlight;
newflashlight.think = flashlight_think;
newflashlight.nextthink = time;
};
void () player_flashlight_toggle =
{
if (self.flashlight_state == FALSE)
{
self.flashlight_state = TRUE;
player_flashlight();
}
else
{
self.flashlight_state = FALSE;
self.flashlight.think = SUB_Remove;
self.flashlight.nextthink = time;
}
};
Thanks.