Forum

How to check an area

Discuss programming in the QuakeC language.

Moderator: InsideQC Admins

How to check an area

Postby Mexicouger » Sat Jul 03, 2010 12:56 am

I don't know how to question this, But I will explain. A teammate of mine asked if There was a way to make it so the player Can't transform from Morph ball to player if he is in an enclosed place. I don't know Much about tracelines, And I don't even know if this is possible. But ALL help would be appreciated. Even your help Downsider :)

This is actually essential, And I have 0% knowledge on doing this. I don't even know where to start.

And on an offtrack note, Why did they use self.weaponmodel, rather than setmodel?

Code: Select all
void() W_SetCurrentAmmo =
{
   if (self.mballtoggle == 1)
   return;

{
   player_run ();      // get out of any weapon firing states

   self.items = self.items - ( self.items & (IT_SHELLS | IT_NAILS | IT_ROCKETS | IT_CELLS) );
   
   if (self.weapon == IT_AXE)
   {
      self.currentammo = 0;
      self.weaponmodel = "progs/v_axe.mdl";
      self.weaponframe = 0;
   }


Thanks
User avatar
Mexicouger
 
Posts: 514
Joined: Sat May 01, 2010 10:12 pm

Postby Arkage » Sat Jul 03, 2010 1:13 am

self.weaponmodel (also called the view model) sets just that the weapon model where as setmodel set the entity's real model.

Since it for the psp you wont have the tracebox option so trace lines it is.

Just trace five lines, forward, back, left, right and up.
Then check how far each traveled and if all have traveled more than half the width (or half of the dir your checking, eg half the height) of the player bounding box its safe-ish to swap back.
User avatar
Arkage
 
Posts: 66
Joined: Thu Nov 19, 2009 4:17 pm

Postby Mexicouger » Sat Jul 03, 2010 3:20 am

Well how would this Code do? I have never used a traceline before, So how about this?
Code: Select all
if (traceline (self.origin , (self.origin+(v_forward * 5)+(v_forward*-5)+(v_right*5)+v_right*-5)+(v_up*5)+v_up*-5 , FALSE , self))
return
else
self.mballtoggle = 0;          //Able to transform back to human



First of all, Can someone define all the parts of a traceline and tell me what they do? I really appreciate it!

EDIT: I am totally off.... Traceline shouldn't be an if statement...
User avatar
Mexicouger
 
Posts: 514
Joined: Sat May 01, 2010 10:12 pm

Postby Arkage » Sat Jul 03, 2010 3:35 am

Trace line is documented in plenty of places, have a look at Quakes qc, or even the flash light tutorial, it sends out a trace line in front of the player so it should be easy pickings. Also try the qc refrance on the front page of the site.
User avatar
Arkage
 
Posts: 66
Joined: Thu Nov 19, 2009 4:17 pm

Postby Mexicouger » Sat Jul 03, 2010 3:52 am

I actually used the Flash light code as a reference.

But I will go see the qc reference And Try my luck.

EDIT: So I figured out that I need to use my Traceline code, but not as an if statement. I should use traceline, and Then what? Tracefraction?
User avatar
Mexicouger
 
Posts: 514
Joined: Sat May 01, 2010 10:12 pm

Postby r00k » Sat Jul 03, 2010 4:47 am

im not sober enough to think but the only thought i can think of is find radius? this will search for an ent witin a given range but if your checked ent isnt there it doesnt matther if the original ent is enclosed?

btw if i remmember correctly .weaponmodel is just for sbar??

wow i need to sober up! :D
r00k
 
Posts: 1110
Joined: Sat Nov 13, 2004 10:39 pm

Postby Mexicouger » Sat Jul 03, 2010 5:05 am

Come back when You have a coding mind :?
User avatar
Mexicouger
 
Posts: 514
Joined: Sat May 01, 2010 10:12 pm

Postby gnounc » Sat Jul 03, 2010 5:19 am

you could do a traceline then check to see if tracefraction is smaller than 1 (meaning it hit something).

and if so dont morph.

the traceline obviously should be as long (or tall) as the amount of space you want in that direction.
User avatar
gnounc
 
Posts: 424
Joined: Mon Apr 06, 2009 6:26 am

Postby gnounc » Sat Jul 03, 2010 5:24 am

Also split that into 4 seperate tracelines

set them all up as variables
so

traceline (self.origin , (self.origin+(v_forward * 5);
x = trace_fraction;

(traceline (self.origin , (self.origin+(v_forward * -5);
y = trace_fraction;

etc

then check that tracefraction for all of those is less than 1

if (x >= 1)
return; //meaning dont morph, so it should be in your morph code

thats the basic idea anyways
User avatar
gnounc
 
Posts: 424
Joined: Mon Apr 06, 2009 6:26 am

Postby Sajt » Sat Jul 03, 2010 5:52 am

I forget, how are you doing the morph ball? Is the player's bbox/hull size actually shrinking in morph ball mode somehow? (The so-called "crouching hull")

If you are, then in the absence of tracebox you should use "walkmove". You setsize to the larger bbox size, check walkmove, and if it fails (meaning you are now intersecting solid geometry), go back to the small one, cancelling the "uncrouch".

But before I go further into this I want to know if the morphball actually has a smaller bbox than the regular player. If not, then this "can't transform from ball to player if in an enclosed place" idea will end up being a big and confusing (to the player) hack.
F. A. Špork, an enlightened nobleman and a great patron of art, had a stately Baroque spa complex built on the banks of the River Labe.
Sajt
 
Posts: 1215
Joined: Sat Oct 16, 2004 3:39 am

Postby Mexicouger » Sat Jul 03, 2010 11:57 pm

Heres the Morphball code(It is subject to change)

Code: Select all
void () CCam;

  void () CCamChasePlayer =
  {
     makevectors (self.v_angle);
     traceline ((self.origin + self.view_ofs),((((self.origin + self.view_ofs)
       + (v_forward * self.camview_z)) + (v_up * self.camview_x)) + (v_right * self.camview_y)),FALSE,self);
     setorigin (self.trigger_field,trace_endpos);
     WriteByte (MSG_ONE,5);
     WriteEntity (MSG_ONE,self.trigger_field);
     self.weaponmodel = "";
  };

  void () CCam =
  {
     local entity camera;
     local entity spot;

     if (self.aflag == FALSE)
     {
        self.aflag = TRUE;
        camera = spawn ();
        spot = spawn ();
        self.trigger_field = camera;
        camera.classname = "camera";
        camera.movetype = MOVETYPE_FLY;
        camera.solid = SOLID_NOT;
        setmodel (camera,"progs/eyes.mdl");
        setsize (camera,'0 0 0','0 0 0');
        makevectors (self.v_angle);
        traceline ((self.origin + self.view_ofs),(((self.origin + self.view_ofs)
           + (v_forward * -64.000))),FALSE,self);
        self.camview = '0 0 -64'; // added
        setorigin (camera,trace_endpos);
        camera.angles = self.angles;
        self.weaponmodel = "";
        msg_entity = self;
        WriteByte (MSG_ONE,5);
        WriteEntity (MSG_ONE,camera);
        WriteByte (MSG_ONE,10.000);
        WriteAngle (MSG_ONE,camera.angles_x);
        WriteAngle (MSG_ONE,camera.angles_y);
        WriteAngle (MSG_ONE,camera.angles_z);
        sprint (self,"Chase Cam On\n");
      self.mballtoggle = self.mballtoggle = 1;
      self.view_ofs = '0 -10 8';
        stuffcmd(self,"cl_forwardspeed 800 \n");
           stuffcmd(self,"cl_backspeed 800 \n");
           stuffcmd(self,"cl_sidespeed 800 \n");
      setsize (self, '-0 -0 -24', '0 0 0');
      }
      else
      {
   if  (traceline (self.origin , (self.origin+(v_forward * 500)) , FALSE , self))
      return;
   else
      {
        self.aflag = FALSE;
        msg_entity = self;
        WriteByte (MSG_ONE,5);
        WriteEntity (MSG_ONE,self);
        WriteByte (MSG_ONE,10);
        WriteAngle (MSG_ONE,self.angles_x);
        WriteAngle (MSG_ONE,self.angles_y);
        WriteAngle (MSG_ONE,self.angles_z);
        remove (self.trigger_field);
        sprint (self,"Chase Cam Off\n");
        W_SetCurrentAmmo ();
      self.mballtoggle = self.mballtoggle = 0;
      self.view_ofs = '0 0 22';
      setsize (self, '-16 -16 -24', '16 16 32');
      W_SetCurrentAmmo ();
      }
     }
  }


I know That I should clean the code up a bit, and For now, I am using the 0 hull until I get in the engine and Change the shambler HULL. So for now, It's 0
User avatar
Mexicouger
 
Posts: 514
Joined: Sat May 01, 2010 10:12 pm

Postby Spike » Sun Jul 04, 2010 12:48 am

neworigin = self.origin;
neworigin_z = neworigin_z - newmins_z + self.mins_z;
tracebox(neworigin, newmins, newmaxs, neworigin, false, self);
if (trace_startsolid)
{
traceissolid_canttransform();
}
else
{
traceisokay_theboxisempty();
self.mins = newmins;
self.maxs = newmaxs;
setorigin(self, neworigin);
setmodelorframeorwhateverelseyouneedhere();
}


I may have gotten the + and - on the second line wrong.
But yeah, if you're modifying the engine already, tracebox is a really easy addition, and does exactly what you need.

This is assuming you actually use a custom hull.
If you want to use points, you'll probably need to use at least 4 traces instead of the tracebox and reject the change if any fail.
Spike
 
Posts: 2892
Joined: Fri Nov 05, 2004 3:12 am
Location: UK

Postby Mexicouger » Sun Jul 04, 2010 1:02 am

Alright thanks. I will test the code. an d There actually isn't really a transform code. It is just self.mballtoggle = 0;//Transform back to human

But thanks. And I suck terribly an engine coding, a matter of fact, I don't have to touch the engine. The bad thing about prime, is that It is gonna be the kurok engine, Nothing more, nothing less... sigh... :cry:
User avatar
Mexicouger
 
Posts: 514
Joined: Sat May 01, 2010 10:12 pm


Return to QuakeC Programming

Who is online

Users browsing this forum: No registered users and 1 guest