Forum

[TUT]trigger_camera - PoC

Discuss programming in the QuakeC language.

Moderator: InsideQC Admins

[TUT]trigger_camera - PoC

Postby Rikku2000 » Wed Apr 15, 2015 7:49 pm

Here i write done a code to use a Camera style like Half-Life maybe a bit other but ist just an Proof of Concept

Image

Update 0.2:
Working well now :) the Camera can now move with "path_corner" and the Trigger will follow.

So let us Start now, first create a new file called "camera.qc" and paste this code inside:
Code: Select all
.entity old_pos;
.float used_camera;
.float cam_timer;

void() train_use;
void() func_train_find;

void() trigger_camera = {
   if (!self.speed)
      self.speed = 64;

   self.cnt = 1;
   self.solid = SOLID_NOT;
   self.movetype = MOVETYPE_PUSH;
   if (self.target) {
      self.use = train_use;

      self.nextthink = self.ltime + 0.1;
      self.think = func_train_find;
   }
};

void() camera_user = {
   if (!self.used_camera)
      self.old_pos = spawn ();

   self.old_pos.solid = SOLID_NOT;
   self.old_pos.movetype = MOVETYPE_NOCLIP;
   setmodel (self.old_pos, "progs/player.mdl");
   self.old_pos.origin = self.origin + '0 0 72';
   self.old_pos.angles = self.angles;
   self.old_pos.fixangle = TRUE;

   setsize (self.old_pos, VEC_HULL_MIN, VEC_HULL_MAX);

   self.old_pos.think = player_stand1;
   self.old_pos.nextthink = time;

   self.cam_timer = time + self.wait;
   self.used_camera = 1;

   player_stand1 ();

   engine_render ();
}

void() camera_return = {
   local entity plr;

   self.state = STATE_BOTTOM;

   if (!self.used_camera)
      return;

   plr = find (world, classname, "player");
   plr.view_ofs = '0 0 22';
   plr.angles = self.old_pos.angles;
   plr.fixangle = TRUE;
   plr.map = self.old_pos.map;
   plr.nextthink = time;
   plr.takedamage = DAMAGE_AIM;
   plr.solid = SOLID_SLIDEBOX;
   plr.movetype = MOVETYPE_WALK;
   setmodel (self.old_pos, "progs/player.mdl");
   plr.origin = self.old_pos.origin + '0 0 1';

   setsize (plr, VEC_HULL_MIN, VEC_HULL_MAX);

   remove (self.old_pos);

   W_SetCurrentAmmo ();

   self.used_camera = 0;
};

void() camera_fire = {
   local entity cam_trg, cam_plr;

   activator = self.enemy;

   SUB_UseTargets ();

   if (self.state == STATE_UP || self.state == STATE_TOP)
      return;

   cam_trg = find (world, classname, "trigger_camera");
   if (!cam_trg)
      error ("no trigger_camera");

   while (1) {
      cam_trg = find (cam_trg, classname, "trigger_camera");
      if (self.target == cam_trg.targetname)
         break;
   }

   cam_plr = find (world, classname, "player");
   while (cam_plr != world) {
      cam_plr.takedamage = DAMAGE_NO;
      cam_plr.solid = SOLID_NOT;
      cam_plr.movetype = MOVETYPE_NONE;

      cam_plr.view_ofs = '0 0 0';
      cam_plr.angles = cam_trg.angles;
      cam_plr.fixangle = TRUE;

      cam_plr.map = self.map;
      cam_plr.modelindex = 0;
      cam_plr.weaponmodel = "";

      cam_plr.origin = cam_trg.origin;

      break;
   }

   if (time > self.cam_timer) {
      self.state = STATE_TOP;

      self.think = camera_return;
      self.nextthink = self.ltime + 0.1;
   } else {
      self.think = camera_fire;
      self.nextthink = self.ltime + 0.0001;
   }
};

void() camera_use = {
   camera_user ();

   self.enemy = activator;
   camera_fire ();
};

void() camera_touch = {
   if (other.classname != "player")
      return;

   camera_user ();

   self.enemy = other;
   camera_fire ();
};

void() func_camera = {
   self.movetype = MOVETYPE_PUSH;
   self.solid = SOLID_BSP;
   setmodel (self, self.model);

   if (!self.wait)
      self.wait = 3;

   self.state = STATE_BOTTOM;

   self.touch = camera_touch;
   self.use = camera_use;
};


Now we open the "plats.qc" and add an small code into "train_next" after "self.wait = 0;":
Code: Select all
   if (self.used_camera)
      self.angles = targ.angles;
This will Change the angles if we use a moving camera.

So here we have 2 new entry for the "quake.fgd" as follow:
Code: Select all
@PointClass base(Appearflags, Targetname) size(-8 -8 -8, 8 8 8) = trigger_camera : "Trigger Camera" [
   target(target_source) : "First stop target"
   speed(integer) : "Speed (units per second)" : 64
]
and
Code: Select all
@SolidClass base(Appearflags, Target) = func_camera : "Camera Button"
[
   wait(integer) : "Hold time" : 10
]
Last edited by Rikku2000 on Sun Apr 19, 2015 12:00 pm, edited 5 times in total.
I am sorry for my English...
User avatar
Rikku2000
 
Posts: 49
Joined: Wed Oct 20, 2010 6:33 pm
Location: Germany

Re: [TUT]trigger_camera - PoC

Postby ceriux » Thu Apr 16, 2015 5:55 am

cool stuff, is that a warhammer weapon though?
User avatar
ceriux
 
Posts: 2220
Joined: Sat Sep 06, 2008 3:30 pm
Location: Indiana, USA

Re: [TUT]trigger_camera - PoC

Postby Rikku2000 » Thu Apr 16, 2015 7:41 am

Okey i update the code to Version 0.2 ist works now like in Half-Life so may some can make Intro Seqs or something. :P
I am sorry for my English...
User avatar
Rikku2000
 
Posts: 49
Joined: Wed Oct 20, 2010 6:33 pm
Location: Germany


Return to QuakeC Programming

Who is online

Users browsing this forum: No registered users and 1 guest