View previous topic :: View next topic |
Author |
Message |
Boss429
Joined: 03 Dec 2006 Posts: 22
|
Posted: Tue Jan 13, 2009 4:06 am Post subject: sticking entities to players |
|
|
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: | 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 |
|
 |
r00k
Joined: 13 Nov 2004 Posts: 483
|
Posted: Tue Jan 13, 2009 6:38 am Post subject: |
|
|
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 |
|
 |
Error Inside3D Staff

Joined: 05 Nov 2004 Posts: 558 Location: VA, USA
|
|
Back to top |
|
 |
Boss429
Joined: 03 Dec 2006 Posts: 22
|
Posted: Wed Jan 14, 2009 5:36 am Post subject: |
|
|
Error, thanks for point that out. But how duth one use this movetype_follow?
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 |
|
 |
Spike
Joined: 05 Nov 2004 Posts: 944 Location: UK
|
Posted: Wed Jan 14, 2009 5:55 pm Post subject: |
|
|
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 |
|
 |
Boss429
Joined: 03 Dec 2006 Posts: 22
|
Posted: Sat Jan 17, 2009 1:26 am Post subject: |
|
|
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 |
|
 |
r00k
Joined: 13 Nov 2004 Posts: 483
|
Posted: Sat Jan 17, 2009 7:21 am Post subject: |
|
|
maybe try time + 0.001 atleast..  |
|
Back to top |
|
 |
Urre

Joined: 05 Nov 2004 Posts: 1073 Location: Sweden
|
Posted: Sat Jan 17, 2009 12:13 pm Post subject: |
|
|
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 |
|
 |
MauveBib

Joined: 04 Nov 2004 Posts: 602
|
Posted: Sat Jan 17, 2009 4:51 pm Post subject: |
|
|
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 |
|
 |
Wazat
Joined: 15 Oct 2004 Posts: 732 Location: Middle 'o the desert, USA
|
Posted: Sun Jan 18, 2009 12:32 am Post subject: |
|
|
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 |
|
 |
MauveBib

Joined: 04 Nov 2004 Posts: 602
|
Posted: Sun Jan 18, 2009 12:49 am Post subject: |
|
|
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 |
|
 |
|