Reversing the angles of an entity
Moderator: InsideQC Admins
10 posts
• Page 1 of 1
Reversing the angles of an entity
Alright, is there a way to reverse the angles of an entity?
IE: projectile flies at a wall, when it hits the wall, its direction is reversed and it fies back towards where it came from?
IE: projectile flies at a wall, when it hits the wall, its direction is reversed and it fies back towards where it came from?
- DusterdooSmock
- Posts: 170
- Joined: Thu Aug 19, 2010 9:58 pm
Re: Reversing the angles of an entity
newvel = oldvel - (normal * ((oldvel*normal) * 2));
will reflect a direction/velocity vector by a normal.
you can bounce an angle by using makevectors/vectoangles to convert that angle into a regular vector and back, though you'd need extensions to retain the roll.
will reflect a direction/velocity vector by a normal.
you can bounce an angle by using makevectors/vectoangles to convert that angle into a regular vector and back, though you'd need extensions to retain the roll.
- Spike
- Posts: 2892
- Joined: Fri Nov 05, 2004 3:12 am
- Location: UK
Re: Reversing the angles of an entity
Spike's entirely code is correct. however, if you want to literally bounce "back towards where it came from", then that's simply a matter of inverting the .velocity vector. (ie: self.velocity = self.velocity * -1).
- necros
- Posts: 77
- Joined: Thu Dec 16, 2004 10:32 pm
Re: Reversing the angles of an entity
Alright, thanks guys. 
- DusterdooSmock
- Posts: 170
- Joined: Thu Aug 19, 2010 9:58 pm
Re: Reversing the angles of an entity
Yes, & the darkplaces bouncemissile is suppose to pretty much do this too. After I tested it, it does work but you still need to add in some -velocity_z on your own (in the entitys touch pointer) if its a projectile such as nails....else they bounce forever with a small chance of ever stopping. Another check to see if they are in water, slime or lava too...I decided to make them a movetype_toss if they are now in a liquid....lava burns em up......
-

Cobalt - Posts: 445
- Joined: Wed Jun 10, 2009 2:58 am
- Location: New England, USA
Re: Reversing the angles of an entity
Ok, now I would like to expand upon this a little bit...

Lets say the projectile flies at wall "A" from location 1.
How would I alter the angles of the projectile so that after it hits wall "A", it flies towards wall "B", and then when it hits wall "B", it changes its angles again so that it flies towards location 2?
And, vice versa; if the projectile flew at wall "B" from location 2, it would alter its angles so that it flies at wall "A", then when it hits wall "A", it alters its angles again so that it flies towards location 1.
Sort of like a "ricochet" effect...

Lets say the projectile flies at wall "A" from location 1.
How would I alter the angles of the projectile so that after it hits wall "A", it flies towards wall "B", and then when it hits wall "B", it changes its angles again so that it flies towards location 2?
And, vice versa; if the projectile flew at wall "B" from location 2, it would alter its angles so that it flies at wall "A", then when it hits wall "A", it alters its angles again so that it flies towards location 1.
Sort of like a "ricochet" effect...
Last edited by DusterdooSmock on Wed Oct 19, 2011 8:04 pm, edited 2 times in total.
- DusterdooSmock
- Posts: 170
- Joined: Thu Aug 19, 2010 9:58 pm
Re: Reversing the angles of an entity
ent.movetype |= MOVETYPE_BOUNCE ?
- r00k
- Posts: 1110
- Joined: Sat Nov 13, 2004 10:39 pm
Re: Reversing the angles of an entity
r00k wrote:ent.movetype |= MOVETYPE_BOUNCE ?
But that won't alter the angles so that the projectile flies in the path that I described...
- DusterdooSmock
- Posts: 170
- Joined: Thu Aug 19, 2010 9:58 pm
Re: Reversing the angles of an entity
DusterdooSmock wrote:r00k wrote:ent.movetype |= MOVETYPE_BOUNCE ?
But that won't alter the angles so that the projectile flies in the path that I described...
if you look in old mods you will find the "pulse rifle"
- Code: Select all
// Modified for the Ultimate Weapons Mod by Andy Brennan.
// =======================================================================
// rebound the pulse spike
void() pulse_rebound =
{
// want the spike to hurt owner now, use maker field to keep
// track of whose spike it is
if (self.state == 0) // if it hasn't bounced yet
{
self.owner = world;
self.state = 1;
}
self.velocity = normalize(self.velocity) * 1000;
self.movetype = MOVETYPE_FLYMISSILE;
self.angles = vectoangles(self.velocity);
self.think = SUB_Remove;
self.nextthink = self.ltime;
};
void() pulse_touch =
{
local float rand;
if (other.solid == SOLID_TRIGGER)
return; // trigger field, do nothing
if (pointcontents(self.origin) == CONTENT_SKY)
{
remove(self);
return;
}
if (self.velocity == '0 0 0')
{
remove (self);
return;
}
if (other.takedamage)
{
// ==========================================================
// BLOOD FIX
// ==========================================================
spawn_touchblood (15);
else
{
// play a ricochet sound
rand = random() * 100;
if (rand < 33)
sound (self, CHAN_AUTO, "ric_1.wav", 1, ATTN_NORM);
else if (rand < 66)
sound (self, CHAN_AUTO, "ric_2.wav", 1, ATTN_NORM);
else
sound (self, CHAN_AUTO, "ric_3.wav", 1, ATTN_NORM);
WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
WriteByte (MSG_BROADCAST, TE_SUPERSPIKE);
WriteCoord (MSG_BROADCAST, self.origin_x);
WriteCoord (MSG_BROADCAST, self.origin_y);
WriteCoord (MSG_BROADCAST, self.origin_z);
// rebound
self.movetype = MOVETYPE_BOUNCE;
self.think = pulse_rebound;
self.ltime = self.nextthink;
self.nextthink = time + 0.1;
return;
}
rand = 15 + random() * 10;
T_Damage (other, self, self.maker, rand);
remove (self);
return;
}
else
{
// play a ricochet sound
rand = random() * 100;
if (rand < 33)
sound (self, CHAN_AUTO, "ric_1.wav", 1, ATTN_NORM);
else if (rand < 66)
sound (self, CHAN_AUTO, "ric_2.wav", 1, ATTN_NORM);
else
sound (self, CHAN_AUTO, "ric_3.wav", 1, ATTN_NORM);
WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
WriteByte (MSG_BROADCAST, TE_SUPERSPIKE);
WriteCoord (MSG_BROADCAST, self.origin_x);
WriteCoord (MSG_BROADCAST, self.origin_y);
WriteCoord (MSG_BROADCAST, self.origin_z);
// rebound
self.movetype = MOVETYPE_BOUNCE;
self.think = pulse_rebound;
self.ltime = self.nextthink;
self.nextthink = time + 0.1;
return;
}
};
void(float ox) W_FirePulseSpikes =
{
local vector dir;
local entity pulse;
makevectors (self.v_angle);
sound (self, CHAN_WEAPON, "pulse_1.wav", 1, ATTN_NORM);
self.ammo_nails = self.ammo_nails - 2;
self.currentammo = self.ammo_nails = self.ammo_nails - 2;
self.punchangle_x = -2;
dir = aim (self, 1000);
pulse = spawn ();
pulse.owner = self;
pulse.maker = self;
pulse.classname = "pulse";
pulse.movetype = MOVETYPE_FLYMISSILE;
pulse.solid = SOLID_BBOX;
// use the state field to determine if it has bounced yet
pulse.state = 0;
pulse.angles = vectoangles(dir);
pulse.velocity = dir * 1000;
pulse.touch = pulse_touch;
pulse.think = SUB_Remove;
pulse.nextthink = time + 3; // time limit
setmodel (pulse, "progs/nail.mdl");
setsize (pulse, VEC_ORIGIN, VEC_ORIGIN);
};
hi, I am nahuel, I love quake and qc.
-

Nahuel - Posts: 492
- Joined: Wed Jan 12, 2011 8:42 pm
- Location: mar del plata
Re: Reversing the angles of an entity
I'll give it a shot. Thanks. 
EDIT:
It works like what I needed. Thank you.
EDIT:
It works like what I needed. Thank you.
- DusterdooSmock
- Posts: 170
- Joined: Thu Aug 19, 2010 9:58 pm
10 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 1 guest