Forum

Players view follows an entity?

Discuss programming in the QuakeC language.

Moderator: InsideQC Admins

Players view follows an entity?

Postby Mexicouger » Tue Jun 14, 2011 5:06 am

I was wondering how I could do this. I don't even know what to start with to make this magic happen. In mind, I have a traceline, and trace_ent.takedamage; the rest is foggy.

And what I mean by players view following an entity, is this;
Let's say you are looking at an enemy and he moves, your center screen will follow the enemy a bit.

Any help would be appreciated.
User avatar
Mexicouger
 
Posts: 514
Joined: Sat May 01, 2010 10:12 pm

Postby r00k » Tue Jun 14, 2011 7:35 am

Here's how I do it in ClanArenaX, when a player dies, the POV of yourself lying on the floor points at your enemy so you can give'em the evil eye! This is called, every frame through playerprethink.
Code: Select all
void() PlayerDeathThink =
{
   local float   forward;
   local vector   angle;

   if (self.flags & FL_ONGROUND)
   {
      forward = vlen (self.velocity);
      forward = forward - 20;
      if (forward <= 0)
         self.velocity = '0 0 0';
      else
         self.velocity = forward * normalize(self.velocity);
   }
   
   //R00k 1.55 look at enemy when dead
   if (self.enemy.classname == "player")
      self.movetarget = self.enemy;

   if (ca_gametype & CA_MATCH_MODE)
   if (self.movetarget.player_flag == PF_PLAYING)
   {
      makevectors (self.v_angle);
      traceline (self.origin, self.movetarget.origin, TRUE, self.movetarget);
      if (trace_fraction == 1)
      {
         angle = angles_bestaim (self.origin, self.movetarget.origin);
         angles_fixangle (angle);
      }
   }
};


The required supporting routines....

angles_bestaim gets the angle, and fixangle rounds the aim by 1/16th

Code: Select all
vector (vector from, vector to) angles_bestaim =
{
   local vector bestaim;

   bestaim = vectoangles ((to - from));
   if ((bestaim_x > 270))
   {
      bestaim_x = (360 - bestaim_x);
      if ((bestaim_x > 78))
      {
         bestaim_x = 78;
      }
   }
   else
   {
      bestaim_x = (0 - bestaim_x);
      if ((bestaim_x < -68))
      {
         bestaim_x = -68;
      }
   }
   return (bestaim);
};

void (vector v) angles_fixangle =
{
   self.ca_oldangle = v;
   
   if (v_x >= 0)   
      self.angles_x = (v_x + 0.0625);
   else
      self.angles_x = (v_x - 0.0625);

   if (v_y >= 0)   
      self.angles_y = (v_y + 0.0625);
   else
      self.angles_y = (v_y - 0.0625);
      
   if (v_x >= 0)   
      self.v_angle_x = (v_x + 0.0625);
   else
      self.v_angle_x = (v_x - 0.0625);
      
   if (v_x >= 0)   
      self.v_angle_y = (v_y + 0.0625);
   else
      self.v_angle_y = (v_y - 0.0625);

   self.fixangle = TRUE;
};


r00k
 
Posts: 1110
Joined: Sat Nov 13, 2004 10:39 pm

Postby Mexicouger » Tue Jun 14, 2011 1:07 pm

Thanks alot Rook! But do you know how to break out of this look if, lets say, you move your mouse really quick, or the player runs away quickly?

But really, thanks!
User avatar
Mexicouger
 
Posts: 514
Joined: Sat May 01, 2010 10:12 pm

Postby r00k » Tue Jun 14, 2011 1:53 pm

You can limit the angle possibly. Like if the angle > 90 then return.

Code: Select all
if (angle < 90)
angles_fixangle (angle);
r00k
 
Posts: 1110
Joined: Sat Nov 13, 2004 10:39 pm

Postby behind_you » Mon Jun 20, 2011 9:26 am

Code: Select all
void (vector v) angles_fixangle =
{
   self.ca_oldangle = v;
   
   if (v_x >= 0)   
      self.angles_x = (v_x + 0.0625);
   else
      self.angles_x = (v_x - 0.0625);

   if (v_y >= 0)   
      self.angles_y = (v_y + 0.0625);
   else
      self.angles_y = (v_y - 0.0625);
      
   if (v_x >= 0)   
      self.v_angle_x = (v_x + 0.0625);
   else
      self.v_angle_x = (v_x - 0.0625);
      
   if (v_x >= 0)   
      self.v_angle_y = (v_y + 0.0625);
   else
      self.v_angle_y = (v_y - 0.0625);

   self.fixangle = TRUE;
};


what's the point of this function? Its not really changing much. 8(
User avatar
behind_you
 
Posts: 237
Joined: Sat Feb 05, 2011 6:57 am
Location: Tripoli, Libya


Return to QuakeC Programming

Who is online

Users browsing this forum: No registered users and 1 guest