Inside3D!
     

sticking entities to players

 
Post new topic   Reply to topic    Inside3d Forums Forum Index -> QuakeC Programming
View previous topic :: View next topic  
Author Message
Boss429



Joined: 03 Dec 2006
Posts: 22

PostPosted: Tue Jan 13, 2009 4:06 am    Post subject: sticking entities to players Reply with quote

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. Sad

Here's my code:
Code:
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.
Back to top
View user's profile Send private message Visit poster's website
r00k



Joined: 13 Nov 2004
Posts: 483

PostPosted: Tue Jan 13, 2009 6:38 am    Post subject: Reply with quote

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:

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...
Back to top
View user's profile Send private message
Error
Inside3D Staff


Joined: 05 Nov 2004
Posts: 558
Location: VA, USA

PostPosted: Tue Jan 13, 2009 11:53 am    Post subject: Reply with quote

if you are using the Darkplaces engine, you can simply use movetype_follow
_________________
Inside3D : Knowledge Is Power
Darkplaces Documentation Wiki
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Boss429



Joined: 03 Dec 2006
Posts: 22

PostPosted: Wed Jan 14, 2009 5:36 am    Post subject: Reply with quote

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

Here's what I tried:
Code:
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?
Back to top
View user's profile Send private message Visit poster's website
Spike



Joined: 05 Nov 2004
Posts: 944
Location: UK

PostPosted: Wed Jan 14, 2009 5:55 pm    Post subject: Reply with quote

esentually:

Code:

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.
_________________
What's a signature?
Back to top
View user's profile Send private message Visit poster's website
Boss429



Joined: 03 Dec 2006
Posts: 22

PostPosted: Sat Jan 17, 2009 1:26 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message Visit poster's website
r00k



Joined: 13 Nov 2004
Posts: 483

PostPosted: Sat Jan 17, 2009 7:21 am    Post subject: Reply with quote

maybe try time + 0.001 atleast.. Very Happy
Back to top
View user's profile Send private message
Urre



Joined: 05 Nov 2004
Posts: 1073
Location: Sweden

PostPosted: Sat Jan 17, 2009 12:13 pm    Post subject: Reply with quote

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...
_________________
Look out for Twigboy
Back to top
View user's profile Send private message Visit poster's website
MauveBib



Joined: 04 Nov 2004
Posts: 602

PostPosted: Sat Jan 17, 2009 4:51 pm    Post subject: Reply with quote

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!
Back to top
View user's profile Send private message
Wazat



Joined: 15 Oct 2004
Posts: 732
Location: Middle 'o the desert, USA

PostPosted: Sun Jan 18, 2009 12:32 am    Post subject: Reply with quote

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:

// 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.
Back to top
View user's profile Send private message MSN Messenger
MauveBib



Joined: 04 Nov 2004
Posts: 602

PostPosted: Sun Jan 18, 2009 12:49 am    Post subject: Reply with quote

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!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Inside3d Forums Forum Index -> QuakeC Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2004 phpBB Group