A sample text widget

Etiam pulvinar consectetur dolor sed malesuada. Ut convallis euismod dolor nec pretium. Nunc ut tristique massa.

Nam sodales mi vitae dolor ullamcorper et vulputate enim accumsan. Morbi orci magna, tincidunt vitae molestie nec, molestie at mi. Nulla nulla lorem, suscipit in posuere in, interdum non magna.

Absolute beginners guide to setattachment (draft)

Absolute beginners guide to setattachment

NOTE: Afaik, setattachment is only compatible with FTE and DP

There’s already a very helpful page on the Quake Wiki, which pretty much covers all you need to know about setattachment, but for those who need more, here’s my unapologetically handholding guide, for absolute beginners, and of course, for a future me who doesn’t remember exactly how I got this working.

Setattachment is a (ssqc) way to connect multiple models together so that they can appear as ‘one model’ but each body part can be controlled seperately. For this ‘step by step’ walkthrough we will make a model consisting of 3 parts: ‘RobotLegs’, ‘RobotTorso’, and ‘Robothead’. Each body part will have its own thinks, but ‘RobotTorso’ and ‘Robothead’ will be ‘child’ entities, permanently connected to ‘RobotLegs’, the ‘parent’ entity.

1. In Blender, make a (crappy boxy test) model with 3 bodyparts, RobotLegs, RobotTorso, and Robothead. Keep the three as seperate objects (ie don’t join them).

2. Make an armature, 3 bones “legs”, “torso”, and “head”, and connect each bone to its respective mesh. [TIP: If it’s a robot, check the weights (weight paint) to make sure that rotating one part has 0 influece on the adjoining part.]

3. Save the Blender file.

4. Export each body part with it’s bone as a seperate iqm (using Salzmans iqm exporter). Note: This example doesn’t need animations (leave the ‘animations’ field blank) TIP: Remember to scale the model up on Export (I’ve been using 8 with great results), otherwise you might have trouble seeing it in-game.


// declare the body parts
#define ROBOT_LEGS "progs/robot_legs.iqm"
#define ROBOT_TORSO "progs/robot_torso.iqm"
#define ROBOT_HEAD "progs/robot_head.iqm"
// precache them
precache_model(ROBOT_HEAD );

[i]Note: I’m not sure if we should attach each part to ‘the part it directly connects to’ (ie other children), or to the parent?[/i]

// spawn the parent entity (the one the others will attach to)
entity Robotlegs = spawn();
		setmodel (Robotlegs, ROBOT_LEGS);
		setorigin(Robotlegs, where_you_want_it_to_spawn); 
		Robotlegs.think = Robotlegsthink;
		Robotlegs.nextthink = time + 1;
// spawn the child entity 1: RobotTorso
entity RobotTorso= spawn();
setmodel (RobotTorso, ROBOT_TORSO);
// attach entity 'RobotTorso' to entity 'Robotlegs', using the RobotTorsobone/tag called 'torso'
		setattachment (RobotTorso, Robotlegs, "torso");
		RobotTorso.think = RobotTorsothink;
		RobotTorso.nextthink = time + 1;
// spawn the child entity 2: RobotTorso
		entity RobotHead = spawn();
		setmodel (RobotHead, ROBOT_HEAD);
// attach entity 'RobotHead' to entity 'RobotTorso', using the bone/tag called 'head'
		setattachment (RobotHead, RobotTorso, "head"); // Q: should it attach to Robotlegs/the parent??
		RobotHead.think = RobotHeadthink;
RobotHead.nextthink = time + 1;

6. Each bodypart now has its’ own ai (Robotlegsthink, RobotTorsothink, and RobotHeadthink).

7. When a child becomes ‘setattached’, it’s origin becomes ‘0 0 0’, and the parent becomes the childs .tag_entity. To get the parents origin, you can go:

vector parent_origin = child.tag_entity.origin;

However we need the *childs* origin, and the way to do that is to use gettaginfo, as described below:

// the parent
void() Robotlegsthink =
// code for the Robotlegs
// origin is self.origin


// child
void() RobotTorsothink =
// code for the RobotTorso
// Note: self.origin is '0 0 0'

// To get RobotTorso's origin:
float robot_torso_bone_number = gettagindex(self, "torso");
vector robot_torso_origin = gettaginfo(self, robot_torso_bone_number);

Leave a Reply




You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Notify me of followup comments via e-mail. You can also subscribe without commenting.