View previous topic :: View next topic |
Author |
Message |
Entar

Joined: 05 Nov 2004 Posts: 422 Location: At my computer
|
Posted: Mon Aug 28, 2006 6:02 pm Post subject: Flying stuff! |
|
|
No, not airplanes, rockets, or hang gliders (those don't actually fly anyway).
I didn't know if this would be worthy of making an entire tutorial for in the tutorials section, just because it's so short, so I posted it here to induce a higher rate of postage (39 cents, can you believe it?) in the forums.
In combat.qc, find
Code: | /*
============
T_RadiusDamage
============
*/
void(entity inflictor, entity attacker, float damage, entity ignore) T_RadiusDamage =
{
local float points;
local entity head;
local vector org;
head = findradius(inflictor.origin, damage+40);
while (head)
{
if (head != ignore)
{
if (head.takedamage)
{
org = head.origin + (head.mins + head.maxs)*0.5;
points = 0.5*vlen (inflictor.origin - org);
if (points < 0)
points = 0;
points = damage - points;
if (head == attacker)
points = points * 0.5;
if (points > 0)
{
if (CanDamage (head, inflictor))
{ // shambler takes half damage from all explosions
if (head.classname == "monster_shambler")
T_Damage (head, inflictor, attacker, points*0.5);
else
T_Damage (head, inflictor, attacker, points);
}
}
}
}
head = head.chain;
}
}; |
Now add a dir vector, and a bit of code inside an else {} after the if (head.takedamage). It should look like this:
Code: | /*
============
T_RadiusDamage
============
*/
void(entity inflictor, entity attacker, float damage, entity ignore) T_RadiusDamage =
{
local float points;
local entity head;
local vector org, dir;
head = findradius(inflictor.origin, damage+40);
while (head)
{
if (head != ignore)
{
if (head.takedamage)
{
org = head.origin + (head.mins + head.maxs)*0.5;
points = 0.5*vlen (inflictor.origin - org);
if (points < 0)
points = 0;
points = damage - points;
if (head == attacker)
points = points * 0.5;
if (points > 0)
{
if (CanDamage (head, inflictor))
{ // shambler takes half damage from all explosions
if (head.classname == "monster_shambler")
T_Damage (head, inflictor, attacker, points*0.5);
else
T_Damage (head, inflictor, attacker, points);
}
}
}
else if (head.movetype == MOVETYPE_BOUNCE)
{
dir = head.origin - (inflictor.absmin + inflictor.absmax) * 0.5;
if (dir_z <= 0)
dir_z = 8;
else
dir_z = dir_z + 8;
dir = normalize(dir);
head.velocity = head.velocity + dir*damage*12;
if (head.flags & FL_ONGROUND)
head.flags = head.flags - FL_ONGROUND;
}
}
head = head.chain;
}
}; |
The new code first gets the direction in which the object needs to be thrown, making sure it's not throwing it at the ground (which wouldn't work very well, because in most cases it's already on the ground).
Next, the velocity is applied to the item being thrown, and the FL_ONGROUND flag is removed, so that it can fly properly.
Now compile, fire up your Quake mod, drop several grenades near each other, and watch the magic!
Note that you can change the *12 to a different value to adjust how much they fly. _________________ woh... feelin woozy... too much cider...
http://entar.quakedev.com
games fascination - My Game Development Blog/Journal

Last edited by Entar on Tue Aug 29, 2006 3:50 pm; edited 1 time in total |
|
Back to top |
|
 |
Dr. Shadowborg Inside3D Staff

Joined: 16 Oct 2004 Posts: 726
|
Posted: Tue Aug 29, 2006 3:08 pm Post subject: |
|
|
This qualifies as being worthy of being placed in the tutorials section. I might do it later if I can find the time, real life has been an absolute biatch lately though... :/ _________________ "Roboto suggests Plasma Bazooka." |
|
Back to top |
|
 |
leileilol

Joined: 15 Oct 2004 Posts: 1321
|
Posted: Tue Aug 29, 2006 3:24 pm Post subject: |
|
|
Looks like a simple modular QuakeC patch to me. Tutorials usually EXPLAIN what the steps actually do, not just "insert here, insert there" _________________
 |
|
Back to top |
|
 |
Entar

Joined: 05 Nov 2004 Posts: 422 Location: At my computer
|
|
Back to top |
|
 |
r00k
Joined: 13 Nov 2004 Posts: 483
|
Posted: Thu Sep 07, 2006 5:18 am Post subject: |
|
|
i think this works the best, without changing TOO much gameplay behavior, also the head != inflictor fixes the explosion...
Code: |
if ((head.movetype == MOVETYPE_BOUNCE) && (head != inflictor))
{
dir = head.origin - (inflictor.absmin + inflictor.absmax) * 0.5;
if (dir_z <= 0)
dir_z = 8;
else
dir_z = dir_z + 8;
dir = normalize(dir);
head.velocity = head.velocity + dir*damage*2;
if (head.flags & FL_ONGROUND)
head.flags = head.flags - FL_ONGROUND;
}
|
 |
|
Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2004 phpBB Group
|