Hanging lamps

From Valve Developer Community
Jump to: navigation, search

This is a tutorial for creating lamp props that swing realistically when shot at.

Introduction

Say you, for example, want a prison_lamp001 type of lamp in your map. It has three types - 001a, 001b and 001c. While type a and b are easy to set up, good for performance, and works well if the player can't reach or shoot at them, a single shot or nudge at these lamp types will reveal that the cord that they're hanging by seem to be made out of rigid steel, which will ruin the realism (and immersion) completely.

To prevent this you can build an advanced rig consisting of a rope (cord), a physics constraint, and the 001c type lamp prop.

The prop

First, create the lamp prop. You can use a number of prop models, prison_lamp001c.mdl, lamp_standard_off01.mdl, lamp_bell_on.mdl and light_industrialbell01_on.mdl being the most suitable alternatives. Normally making the model a prop_physics will suffice, but the prison_lamp001c lacks physics data (making it a prop_static like its other versions), so in order to prevent it from being deleted in-game due to violating prop type standards, we will need to make it a prop_physics_override instead. Name the lamp so that it can be parented by the cord and the constraint later on.

The rope

Secondly, set up the rope as normal - a move_rope attached at the ceiling, leading to a keyframe_rope where the lamp is going to be hanging from. (See Cables and Ropes if you are uncertain.) In the Parent field of the keyframe_rope, insert the name of the lamp prop, and give it a width (1-64) of 1.

The constraint

The biggest worry about setting up hanging lamps is which constraint to use. Instinctively a phys_lengthconstraint would be the obvious choice, but in-game this constraint make the lamp bounce around like possessed, even with added iterations from a phys_constraintsystem. (The reason for this is that the weight of the lamp keeps tugging on the constraint.)

Other tutorials uses a phys_ballsocket to eliminate the bouncing, but instead creating a result similar to if just a ballsocket and a type 001a or type 001b prop were to be used.

I suggest using a phys_spring because it lets you control the "bounciness" (seen using the phys_lengthconstraint). Set Entity 1 to the name of the lamp prop, the Spring Length to only a third of the distance between the ceiling and the lamp (because the weight of the lamp will still be tugging at the constraint, stretching it), String Constant to about 100, and Damping Constant to 16.0 for a good result. (Feel free to experiment with the values.) To prevent "rubber" cords, you can set Break on Length to a reasonable length. Also check the Force only on stretch flag.