Forum

darkplaces help with attach entities

Discuss programming in the QuakeC language.

Moderator: InsideQC Admins

darkplaces help with attach entities

Postby RooT » Fri Oct 21, 2005 3:55 am

ive been reading through the darkplaces.qc trying to understand the quake3 attack entity script, and what ive gathered is that it allows seemless movement of one entity with another, such as say a weapon in the players hand (not first person tho) . Lets just say I wanted to make a hat or something, that you can have attached to players head. how do i set the attachment point for the hat? i think its tag_index but im not quite sure what it wants me to do with it :P

if someone could explain this a little for me i would much appreciate it. thanks!
-root
My mod site!
Mod Status:
Turret Defense: 30%
UPS: 45%
User avatar
RooT
 
Posts: 40
Joined: Wed Sep 07, 2005 1:28 am

Postby Supa » Fri Oct 21, 2005 5:56 pm

To just attach an entity to an object, you need to call:

Code: Select all
setattachment(entity (the entity you want to attach), entity (the entity you want to attach it to), string (name of the tag to attach the entity to, ie 'tag_foo');

For example:

setattachment(foo, self, "tag_torso");


Of course, you'll need a tag to attach it to or the attacher entity will just attach to the center of the attachee.
Once an entity is attached to another, .tag_entity will return which entity it's attached to and .tag_index will return the index of the tag (tag_index of 2 would be the second tag, for instance). One last note, once an entity is attached to something it ignores collision, so you can't do things like hand held shields easily (You *can* do them, it's just harder).

[Edit: I managed to confuse even myself so I added an example to better explain what I was trying to say.]
aut viam inveniam aut faciam
User avatar
Supa
 
Posts: 164
Joined: Tue Oct 26, 2004 8:10 am

ahh

Postby RooT » Fri Oct 21, 2005 8:52 pm

i think i get it thanks man, hope to turn out something useful with all that work you put in for me :P thanks again
-root
My mod site!
Mod Status:
Turret Defense: 30%
UPS: 45%
User avatar
RooT
 
Posts: 40
Joined: Wed Sep 07, 2005 1:28 am

Postby jimmmy » Mon Nov 07, 2005 9:59 am

Supa wrote:One last note, once an entity is attached to something it ignores collision, so you can't do things like hand held shields easily (You *can* do them, it's just harder).


What's the best way to do attachments but still have collisions?
Use MOVETYPE_FOLLOW? Or attach the entity and have an invisible 'bounding box' using' MOVETYPE_FOLLOW or something similar?

Thanks.
jimmmy
 
Posts: 5
Joined: Mon Nov 07, 2005 7:27 am
Location: Australia

Postby Supa » Fri Nov 11, 2005 9:44 am

jimmmy wrote:What's the best way to do attachments but still have collisions?
Use MOVETYPE_FOLLOW? Or attach the entity and have an invisible 'bounding box' using' MOVETYPE_FOLLOW or something similar?


Both the MOVETYPE_FOLLOW (You'd actaully need MOVETYPE_NONE) and the bounding box (Again, MOVETYPE_NONE) method will work (The bounding box method will result in another entity per player though *and* the bounding box needs to be a reasonable duplicate of the shield model). Use DP_QC_GETTAGINFO to get the forward vectors of the shield tag and align the entity to match. Note that you're going to need to update the position and angles of the 'shield' every frame.

Note that if you use this method you will need to modify how your weaponset works or you'll get things hitting the bounding box of the shield when they shouldn't. (Much like firing a little over a grunts head and still hitting the grunt) For traceline weapons you just need to use MOVE_HITMODEL when you call traceline, please check dpextensions.qc for details on this. For projectiles you'll need to trace out from the front of the projectile a little each frame, again using MOVE_HITMODEL. I haven't actually tried using this with projectiles though, so I could be wrong.

'Hope this helps and let me know how it works, okay? =)
aut viam inveniam aut faciam
User avatar
Supa
 
Posts: 164
Joined: Tue Oct 26, 2004 8:10 am

Postby Sajt » Sat Nov 12, 2005 1:13 am

ACtually if you want to have it work with projectiles as well, set the shield's solid to SOLID_BSP.
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 jimmmy » Tue Nov 22, 2005 3:24 am

Thanks for that help, however I don't seem to have my implementation quite right and aren't sure exactly what I'm doing wrong. I'm not familiar enough with quake c. :oops:

I'm using noctrun's md3 example code (http://mitglied.lycos.de/noctrun/q1md3/ ) as a base and fiddling around with md3 models using that (I'm experimenting before I waste any of my art orientated friend's time), my plan was to remove its usage of attach so that each body section can handle collisions with traces via MOVE_HITMODEL for simple location damage type stuff.

So far this is what I have:

Code: Select all
void(entity body) AttachBodyParts =
{
   local float torsoTagIndex;
   torsoTagIndex = gettagindex(body, "tag_torso");
   gettaginfo(body, torsoTagIndex);
   setorigin (body.torso, v_forward);
   body.torso.angles = v_forward;
}

void() UpdatePeopleModels =
{
   local entity people;
   people = find(world, classname, "monster_army");
   while (people)
   {
      AttachBodyParts(people);
      people = find(people, classname, "monster_army");
      // loop to next monster in sequence (the start parameter is now person)
   }
}


UpdatePeopleModels is temporary while I get the basic code working, afterwards I'll do something more efficient. I'm just testing it out with the ranger replacement for the grunt / soldier.

I call AttachBodyParts from the setup function (setq3model in noctrun's code) and UpdatePeopleModels every frame like you said.


Code: Select all
void(entity person, string mdl_legs, string mdl_torso, string mdl_head) setq3model =
{
   if (person == world)
   {
      return;
   }
   //don't add new torso/head while respawning in multiplayer
   if (person.md3partsspawned == FALSE)
   {
      person.torso = spawn();
      person.head = spawn();
      person.md3partsspawned = TRUE;
   }
   setmodel(person, mdl_legs);
   setmodel(person.torso, mdl_torso);
   setmodel(person.head, mdl_head);

   person.head.exteriormodeltoclient = person;
   person.torso.exteriormodeltoclient = person;
   
   AttachBodyParts(person);
//   setattachment(person.torso, person, "tag_torso");
//   setattachment(person.head, person.torso, "tag_head");

   person.torso.think = md3_player_animate_torso;
   person.torso.nextthink = time + 0.1;
};


So I've commented out the setattachment bits of code and replaced them with AttachBodyParts (which doesn't do the head yet). But it doesn't seem to be working and my attempts at trying other methods and figuring out why have been rather unsuccessful.

Thanks for your help so far and any you can give me with this next bit.
jimmmy
 
Posts: 5
Joined: Mon Nov 07, 2005 7:27 am
Location: Australia


Return to QuakeC Programming

Who is online

Users browsing this forum: No registered users and 1 guest