Forum

sticking entities to players

Discuss programming in the QuakeC language.

Moderator: InsideQC Admins

sticking entities to players

Postby Boss429 » Tue Jan 13, 2009 4:06 am

Hey all. I was dabbling a bit in QuakeC trying to make an entity to stick to the player.
Its suppose to be a vehicle that sicks to you when you touch it (simulating you getting in the car) and then lets you drive off...
The sticking part works until your car touches a wall and then the car kind of falls off your player model. :(

Here's my code:
Code: Select all
void() car_touch;

void() item_vehi =
{
   self.touch = car_touch;
   setmodel(self, "models/car.mdl");
   setsize (self, '0 0 0', '32 32 56');
   StartItem ();
};

void() car_touch =
{
   if (other.classname != "player") //monsters can't drive
      return;

   //self.solid = SOLID_NOT; //make the item not solid
      self.origin = other.origin;
      if ( (self.velocity == VEC_ORIGIN) )
         self.avelocity = VEC_ORIGIN;
   sv_friction = sv_friction * .5;
   sv_stopspeed = sv_stopspeed * 4;
   
};


I tried to remedy this by using the self.solid = SOLID_NOT; line as you can see, but this just made the player drop the entity instantly.
Is there a quick fix for this?
Any help is appreciated.
Boss429
 
Posts: 39
Joined: Sun Dec 03, 2006 7:29 pm

Postby r00k » Tue Jan 13, 2009 6:38 am

well off the top of my head, you can set the car's .think function and .nextthink = time + 0.05
and update the car's origin to the player's origin 20 times per sec.

Code: Select all
void() drive_me_crazy =
{
   if (self.movetarget)
   {
      setorigin(self, self.movetarget.origin);
      self.angles = self.movetarget.v_angle;
      self.v_angle = self.movetarget.v_angle;
      self.fixangle = TRUE;

      self.nextthink = time + 0.05;   
   }
};

void() car_touch =
{
   if (other.classname != "player") //monsters can't drive
      return;
   self.movetarget = other;
   self.think = drive_me_crazy;
   self.nextthink = time + 0.05;   
};

of course you also must create some code to release ownership of the car after they get out...
r00k
 
Posts: 1110
Joined: Sat Nov 13, 2004 10:39 pm

Postby Error » Tue Jan 13, 2009 11:53 am

if you are using the Darkplaces engine, you can simply use movetype_follow
User avatar
Error
InsideQC Staff
 
Posts: 865
Joined: Fri Nov 05, 2004 5:15 am
Location: VA, USA

Postby Boss429 » Wed Jan 14, 2009 5:36 am

Error, thanks for point that out. But how duth one use this movetype_follow? :?

Here's what I tried:
Code: Select all
void() car_touch;

void() item_vehi =
{
   self.touch = car_touch;
   setmodel(self, "models/car.mdl");
   setsize (self, '0 0 0', '32 32 56');
   self.movetype = MOVETYPE_FOLLOW;
   StartItem ();
};

void() car_touch =
{
   if (other.classname != "player") //monsters can't drive
      return;

   //self.solid = SOLID_NOT; //make the item not solid
        self.aiment = other;
   sv_friction = sv_friction * .5;
   sv_stopspeed = sv_stopspeed * 4;
   
};

am I missing something?
Boss429
 
Posts: 39
Joined: Sun Dec 03, 2006 7:29 pm

Postby Spike » Wed Jan 14, 2009 5:55 pm

esentually:

Code: Select all
void() movetype_follow_think =
{
 makevectors(self.aiment.angles);
 self.origin = self.aiment.origin + v_forward*self.view_ofs_x +  v_right*self.view_ofs_y + v_up*self.view_ofs_z;
 self.angles = self.v_angle + self.aiment.angles;
};


that is, put the following ent view_ofs units away from the followed origin based on the followed's angles.
you can rotate the followed ent around the owner by changing punchangle too.
or something like that.

note that movetype_follow can be a frame behind, depending on spawn sequence. it is not practically usable on player entities.
Spike
 
Posts: 2892
Joined: Fri Nov 05, 2004 3:12 am
Location: UK

Postby Boss429 » Sat Jan 17, 2009 1:26 am

Thanks for the heads up Spike.
I tried your method r00k and it worked great for the most part.
.nextthink = time + 0.05 was too slow so I changed it to .nextthink = time;
Thanks for the help.
Boss429
 
Posts: 39
Joined: Sun Dec 03, 2006 7:29 pm

Postby r00k » Sat Jan 17, 2009 7:21 am

maybe try time + 0.001 atleast.. :D
r00k
 
Posts: 1110
Joined: Sat Nov 13, 2004 10:39 pm

Postby Urre » Sat Jan 17, 2009 12:13 pm

r00k: why? Without nextthink = time; TWIG wouldn't work, for example. Or is it a QW mod we're talking about here, I've heard QW doesn't like entities thinking every frame...
I was once a Quake modder
User avatar
Urre
 
Posts: 1109
Joined: Fri Nov 05, 2004 2:36 am
Location: Moon

Postby MauveBib » Sat Jan 17, 2009 4:51 pm

r00k: nexthink = time is essentially for this sort of thing, as it means it updates every frame. It won't get stuck in a loop if that's what you're worried about, it just means it updates every frame.

Of course depending on entity order the sticking entity may end up one frame behind, which is a problem I'm having in DiD2.

Any solutions? Other than md3 tagging...
Apathy Now!
User avatar
MauveBib
 
Posts: 634
Joined: Thu Nov 04, 2004 1:22 am

Postby Wazat » Sun Jan 18, 2009 12:32 am

Mauve: Well, instead of having each individual piece think independently, you can instead have the main core entity do the thinking, and it updates everything all at once (i.e. in its .think or in player post think). When it moves or turns etc, it updates its child pieces. The example below has a parts list as a linked list (instead of a .entity for each possible part):

Code: Select all
// position/angle has changed.  Update all pieces following me
head = self.attachedPart;
while(head != world) {
  head.origin = self.origin + v_forward * head.view_ofs_x + v_right * head.view_ofs.y + v_up * head.view_ofs.z;
  // also do angles, etc

  head = head.attachedPart;
}


Or use MOVETYPE_FOLLOW in DP or another supporting engine, which should presumably keep them fairly effectively attached (not sure how clean it is).
When my computer inevitably explodes and kills me, my cat inherits everything I own. He may be the only one capable of continuing my work.
Wazat
 
Posts: 771
Joined: Fri Oct 15, 2004 9:50 pm
Location: Middle 'o the desert, USA

Postby MauveBib » Sun Jan 18, 2009 12:49 am

wazat: not a bad idea, I'll give it a go. MOVETYPE_FOLLOW has the same issue as .think, it is sometimes a frame behind depending on entity order.
Apathy Now!
User avatar
MauveBib
 
Posts: 634
Joined: Thu Nov 04, 2004 1:22 am


Return to QuakeC Programming

Who is online

Users browsing this forum: No registered users and 1 guest