2 // tZorks trigger impulse / gravity
8 // targeted (directional) mode
9 void trigger_impulse_touch1()
15 if (self.active != ACTIVE_ACTIVE)
18 if (!isPushable(other))
23 targ = find(world, targetname, self.target);
26 objerror("trigger_force without a (valid) .target!\n");
31 str = min(self.radius, vlen(self.origin - other.origin));
34 str = (str / self.radius) * self.strength;
35 else if(self.falloff == 2)
36 str = (1 - (str / self.radius)) * self.strength;
40 pushdeltatime = time - other.lastpushtime;
41 if (pushdeltatime > 0.15) pushdeltatime = 0;
42 other.lastpushtime = time;
43 if(!pushdeltatime) return;
45 other.velocity = other.velocity + normalize(targ.origin - self.origin) * str * pushdeltatime;
46 other.flags &= ~FL_ONGROUND;
47 UpdateCSQCProjectile(other);
50 // Directionless (accelerator/decelerator) mode
51 void trigger_impulse_touch2()
55 if (self.active != ACTIVE_ACTIVE)
58 if (!isPushable(other))
63 pushdeltatime = time - other.lastpushtime;
64 if (pushdeltatime > 0.15) pushdeltatime = 0;
65 other.lastpushtime = time;
66 if(!pushdeltatime) return;
68 // div0: ticrate independent, 1 = identity (not 20)
69 other.velocity = other.velocity * pow(self.strength, pushdeltatime);
70 UpdateCSQCProjectile(other);
73 // Spherical (gravity/repulsor) mode
74 void trigger_impulse_touch3()
79 if (self.active != ACTIVE_ACTIVE)
82 if (!isPushable(other))
87 pushdeltatime = time - other.lastpushtime;
88 if (pushdeltatime > 0.15) pushdeltatime = 0;
89 other.lastpushtime = time;
90 if(!pushdeltatime) return;
92 setsize(self, '-1 -1 -1' * self.radius,'1 1 1' * self.radius);
94 str = min(self.radius, vlen(self.origin - other.origin));
97 str = (1 - str / self.radius) * self.strength; // 1 in the inside
98 else if(self.falloff == 2)
99 str = (str / self.radius) * self.strength; // 0 in the inside
103 other.velocity = other.velocity + normalize(other.origin - self.origin) * str * pushdeltatime;
104 UpdateCSQCProjectile(other);
107 /*QUAKED spawnfunc_trigger_impulse (.5 .5 .5) ?
108 -------- KEYS --------
109 target : If this is set, this points to the spawnfunc_target_position to which the player will get pushed.
110 If not, this trigger acts like a damper/accelerator field.
112 strength : This is how mutch force to add in the direction of .target each second
113 when .target is set. If not, this is hoe mutch to slow down/accelerate
114 someting cought inside this trigger. (1=no change, 0,5 half speed rougthly each tic, 2 = doubble)
116 radius : If set, act as a spherical device rather then a liniar one.
118 falloff : 0 = none, 1 = liniar, 2 = inverted liniar
120 -------- NOTES --------
121 Use a brush textured with common/origin in the trigger entity to determine the origin of the force
122 in directional and sperical mode. For damper/accelerator mode this is not nessesary (and has no effect).
125 void spawnfunc_trigger_impulse()
127 self.active = ACTIVE_ACTIVE;
132 if(!self.strength) self.strength = 2000 * autocvar_g_triggerimpulse_radial_multiplier;
133 setorigin(self, self.origin);
134 setsize(self, '-1 -1 -1' * self.radius,'1 1 1' * self.radius);
135 self.touch = trigger_impulse_touch3;
141 if(!self.strength) self.strength = 950 * autocvar_g_triggerimpulse_directional_multiplier;
142 self.touch = trigger_impulse_touch1;
146 if(!self.strength) self.strength = 0.9;
147 self.strength = pow(self.strength, autocvar_g_triggerimpulse_accel_power) * autocvar_g_triggerimpulse_accel_multiplier;
148 self.touch = trigger_impulse_touch2;