How to make a rocket fly on a spiral trajectory?
How to make a rocket fly on a spiral trajectory?
I think that should be easy, but I have no clue how to code this. I want to make 2 rockets launched simultaneously from the rocket launcher fly on a spiral pattern, but also towards to where I aimed. Maybe I should spawn an invisible entity to determine the center point which both rockets will fly around?
-
- Posts: 2126
- Joined: Sat Nov 25, 2006 1:49 pm
Re: How to make a rocket fly on a spiral trajectory?
Since both rockets will hit the same point, I'd suggest you to go the easy way: make a new missile model, using frame groups to animate the rockets spiralling.
I know FrikaC made a cgi-bin version of the quakec interpreter once and wrote part of his website in QuakeC (LordHavoc)
Re: How to make a rocket fly on a spiral trajectory?
I don't want the rockets to hit *exactly* the same point, depending on the position they will hit a wall, it'll be more likely they will hit a wall side by side or vertically, etc. And I prefer the hard way, 2 individual rockets spiralling, so it's more 'realistic' and there will be 2 trails making a cool corkscrew as they fly.
Re: How to make a rocket fly on a spiral trajectory?
makevectors(self.enemy.angles);
setorigin(self, self.enemy.origin + (v_right * sin(time)) + (v_up * cos(time)));
'self' will then orbit 'self.enemy'. update its angles_z at the same time and you can make the rocket revolve also.
really though you probably want to update the rocket's velocity such that it moves towards the specified point instead (although you may find aiming short of it is smoother due to greater reliability). then you don't have the rocket suddenly appearing inside a wall and thus either damaging things through it or damaging nothing.
setorigin(self, self.enemy.origin + (v_right * sin(time)) + (v_up * cos(time)));
'self' will then orbit 'self.enemy'. update its angles_z at the same time and you can make the rocket revolve also.
really though you probably want to update the rocket's velocity such that it moves towards the specified point instead (although you may find aiming short of it is smoother due to greater reliability). then you don't have the rocket suddenly appearing inside a wall and thus either damaging things through it or damaging nothing.
Re: How to make a rocket fly on a spiral trajectory?
Yeah, changing the velocity should be the appropriate solution. It should look something like the following...Spike wrote:really though you probably want to update the rocket's velocity such that it moves towards the specified point instead
Add this to weapons.qc, right above the W_FireRocket function:
Code: Select all
void () W_UpdateRocket =
{
local entity missile;
local vector f, r, u;
missile = self;
makevectors (missile.angles);
f = v_forward * 1000;
// spirals 32 units per second
r = v_right * 32 * sin (time);
u = v_up * 32 * cos (time);
missile.velocity = normalize (f + r + u) * 1000;
// missile.angles = vectoangles (missile.velocity); // not sure about this line
missile.nextthink = time + 0.05;
if (missile.attack_finished < time)
remove (missile);
}
Code: Select all
void() W_FireRocket =
{
[...]
// set missile duration
missile.nextthink = time + 5;
missile.think = SUB_Remove;
[...]
}
Code: Select all
void() W_FireRocket =
{
[...]
// set missile duration
missile.attack_finished = time + 5;
missile.nextthink = time + 0.05; // 20 updates per second
missile.think = W_UpdateRocket;
[...]
}
Re: How to make a rocket fly on a spiral trajectory?
Got it to work, using this code:
t_width will determine if rocket will go clockwise or counter-clockwise. Two rockets are launched spiralling at opposed directions, doing twice the damage one rocket would do, also using 2 rockets a shot.
This was the result:
http://www.youtube.com/watch?v=cVdQGMon ... e=youtu.be
Code: Select all
void() SpiralThink =
{
local vector ang;
self.nextthink = time + 0.05;
if (self.health < time)
{
if (self.owner.rl_detonation == 1)
RocketExplode ();
else
remove(self);
return;
}
if (self.t_width)
{
if (self.frags == 0)
self.angles_y = self.angles_y - 10;
else if (self.frags == 1)
self.angles_x = self.angles_x + 10;
else if (self.frags == 2)
self.angles_y = self.angles_y + 10;
else if (self.frags == 3)
self.angles_y = self.angles_y + 10;
else if (self.frags == 4)
self.angles_x = self.angles_x - 10;
else if (self.frags == 5)
self.angles_x = self.angles_x - 10;
else if (self.frags == 6)
self.angles_y = self.angles_y - 10;
else if (self.frags == 7)
self.angles_y = self.angles_y - 10;
else if (self.frags == 8)
self.angles_x = self.angles_x + 10;
else if (self.frags == 9)
self.angles_x = self.angles_x + 10;
else if (self.frags == 10)
self.angles_y = self.angles_y + 10;
else if (self.frags == 11)
self.angles_y = self.angles_y + 10;
else if (self.frags == 12)
self.angles_x = self.angles_x - 10;
else if (self.frags == 13)
self.angles_x = self.angles_x - 10;
}
else
{
if (self.frags == 0)
self.angles_y = self.angles_y + 10;
else if (self.frags == 1)
self.angles_x = self.angles_x - 10;
else if (self.frags == 2)
self.angles_y = self.angles_y - 10;
else if (self.frags == 3)
self.angles_y = self.angles_y - 10;
else if (self.frags == 4)
self.angles_x = self.angles_x + 10;
else if (self.frags == 5)
self.angles_x = self.angles_x + 10;
else if (self.frags == 6)
self.angles_y = self.angles_y + 10;
else if (self.frags == 7)
self.angles_y = self.angles_y + 10;
else if (self.frags == 8)
self.angles_x = self.angles_x - 10;
else if (self.frags == 9)
self.angles_x = self.angles_x - 10;
else if (self.frags == 10)
self.angles_y = self.angles_y - 10;
else if (self.frags == 11)
self.angles_y = self.angles_y - 10;
else if (self.frags == 12)
self.angles_x = self.angles_x + 10;
else if (self.frags == 13)
self.angles_x = self.angles_x + 10;
}
self.frags = self.frags + 1;
if (self.frags >= 13)
self.frags = 5;
ang = self.angles;
ang_x = ang_x * -1;
makevectors (ang);
self.velocity = v_forward * 1000;
if (self.owner.rl_detonation == 2)
RocketCheckExplode2 ();
};
This was the result:
http://www.youtube.com/watch?v=cVdQGMon ... e=youtu.be
Re: How to make a rocket fly on a spiral trajectory?
Orion can you post the whole code for this one?
Orion wrote:Got it to work, using this code:
t_width will determine if rocket will go clockwise or counter-clockwise. Two rockets are launched spiralling at opposed directions, doing twice the damage one rocket would do, also using 2 rockets a shot.Code: Select all
void() SpiralThink = { local vector ang; self.nextthink = time + 0.05; if (self.health < time) { if (self.owner.rl_detonation == 1) RocketExplode (); else remove(self); return; } if (self.t_width) { if (self.frags == 0) self.angles_y = self.angles_y - 10; else if (self.frags == 1) self.angles_x = self.angles_x + 10; else if (self.frags == 2) self.angles_y = self.angles_y + 10; else if (self.frags == 3) self.angles_y = self.angles_y + 10; else if (self.frags == 4) self.angles_x = self.angles_x - 10; else if (self.frags == 5) self.angles_x = self.angles_x - 10; else if (self.frags == 6) self.angles_y = self.angles_y - 10; else if (self.frags == 7) self.angles_y = self.angles_y - 10; else if (self.frags == 8) self.angles_x = self.angles_x + 10; else if (self.frags == 9) self.angles_x = self.angles_x + 10; else if (self.frags == 10) self.angles_y = self.angles_y + 10; else if (self.frags == 11) self.angles_y = self.angles_y + 10; else if (self.frags == 12) self.angles_x = self.angles_x - 10; else if (self.frags == 13) self.angles_x = self.angles_x - 10; } else { if (self.frags == 0) self.angles_y = self.angles_y + 10; else if (self.frags == 1) self.angles_x = self.angles_x - 10; else if (self.frags == 2) self.angles_y = self.angles_y - 10; else if (self.frags == 3) self.angles_y = self.angles_y - 10; else if (self.frags == 4) self.angles_x = self.angles_x + 10; else if (self.frags == 5) self.angles_x = self.angles_x + 10; else if (self.frags == 6) self.angles_y = self.angles_y + 10; else if (self.frags == 7) self.angles_y = self.angles_y + 10; else if (self.frags == 8) self.angles_x = self.angles_x - 10; else if (self.frags == 9) self.angles_x = self.angles_x - 10; else if (self.frags == 10) self.angles_y = self.angles_y - 10; else if (self.frags == 11) self.angles_y = self.angles_y - 10; else if (self.frags == 12) self.angles_x = self.angles_x + 10; else if (self.frags == 13) self.angles_x = self.angles_x + 10; } self.frags = self.frags + 1; if (self.frags >= 13) self.frags = 5; ang = self.angles; ang_x = ang_x * -1; makevectors (ang); self.velocity = v_forward * 1000; if (self.owner.rl_detonation == 2) RocketCheckExplode2 (); };
This was the result:
http://www.youtube.com/watch?v=cVdQGMon ... e=youtu.be
Re: How to make a rocket fly on a spiral trajectory?
Orion that's cool!
Re: How to make a rocket fly on a spiral trajectory?
I'll post the clean code for you, because this one I used there is some mod-specific parameters.
These are the clean SpiralThink() and W_FireSecondRocket(), paste them just above W_FireRocket():
And this is the clean W_FireRocket(), replace the whole function with this:
These are the clean SpiralThink() and W_FireSecondRocket(), paste them just above W_FireRocket():
Code: Select all
void() SpiralThink =
{
local vector ang;
self.nextthink = time + 0.05;
if (self.health < time)
{
remove(self);
return;
}
if (self.t_width)
{
if (self.frags == 0)
self.angles_y = self.angles_y - 10;
else if (self.frags == 1)
self.angles_x = self.angles_x + 10;
else if (self.frags == 2)
self.angles_y = self.angles_y + 10;
else if (self.frags == 3)
self.angles_y = self.angles_y + 10;
else if (self.frags == 4)
self.angles_x = self.angles_x - 10;
else if (self.frags == 5)
self.angles_x = self.angles_x - 10;
else if (self.frags == 6)
self.angles_y = self.angles_y - 10;
else if (self.frags == 7)
self.angles_y = self.angles_y - 10;
else if (self.frags == 8)
self.angles_x = self.angles_x + 10;
else if (self.frags == 9)
self.angles_x = self.angles_x + 10;
else if (self.frags == 10)
self.angles_y = self.angles_y + 10;
else if (self.frags == 11)
self.angles_y = self.angles_y + 10;
else if (self.frags == 12)
self.angles_x = self.angles_x - 10;
else if (self.frags == 13)
self.angles_x = self.angles_x - 10;
}
else
{
if (self.frags == 0)
self.angles_y = self.angles_y + 10;
else if (self.frags == 1)
self.angles_x = self.angles_x - 10;
else if (self.frags == 2)
self.angles_y = self.angles_y - 10;
else if (self.frags == 3)
self.angles_y = self.angles_y - 10;
else if (self.frags == 4)
self.angles_x = self.angles_x + 10;
else if (self.frags == 5)
self.angles_x = self.angles_x + 10;
else if (self.frags == 6)
self.angles_y = self.angles_y + 10;
else if (self.frags == 7)
self.angles_y = self.angles_y + 10;
else if (self.frags == 8)
self.angles_x = self.angles_x - 10;
else if (self.frags == 9)
self.angles_x = self.angles_x - 10;
else if (self.frags == 10)
self.angles_y = self.angles_y - 10;
else if (self.frags == 11)
self.angles_y = self.angles_y - 10;
else if (self.frags == 12)
self.angles_x = self.angles_x + 10;
else if (self.frags == 13)
self.angles_x = self.angles_x + 10;
}
self.frags = self.frags + 1;
if (self.frags >= 13)
self.frags = 5;
ang = self.angles;
ang_x = ang_x * -1;
makevectors (ang);
self.velocity = v_forward * 1000;
};
void() W_FireSecondRocket =
{
local entity missile;
missile = spawn ();
missile.owner = self;
missile.movetype = MOVETYPE_FLYMISSILE;
missile.solid = SOLID_BBOX;
missile.classname = "missile";
// set missile speed
makevectors (self.v_angle);
missile.velocity = v_forward;
missile.velocity = missile.velocity * 1000;
missile.angles = vectoangles(missile.velocity);
missile.touch = T_MissileTouch;
// set missile duration
missile.health = time + 5;
missile.t_width = 1;
missile.nextthink = time + 0.05;
missile.think = SpiralThink;
setmodel (missile, "progs/missile.mdl");
setsize (missile, '0 0 0', '0 0 0');
setorigin (missile, self.origin + v_forward*8 + '0 0 16');
};
Code: Select all
void() W_FireRocket =
{
local entity missile;
if (self.ammo_rockets < 2)
{
sprint (self, "Not enough rockets!\n");
player_run ();
return;
}
self.currentammo = self.ammo_rockets = self.ammo_rockets - 2;
sound (self, CHAN_WEAPON, "weapons/sgun1.wav", 1, ATTN_NORM);
self.punchangle_x = -2;
W_FireSecondRocket ();
missile = spawn ();
missile.owner = self;
missile.movetype = MOVETYPE_FLYMISSILE;
missile.solid = SOLID_BBOX;
missile.classname = "missile";
// set missile speed
makevectors (self.v_angle);
missile.velocity = v_forward;
missile.velocity = missile.velocity * 1000;
missile.angles = vectoangles(missile.velocity);
missile.touch = T_MissileTouch;
// set missile duration
missile.health = time + 5;
missile.nextthink = time + 0.05;
missile.think = SpiralThink;
setmodel (missile, "progs/missile.mdl");
setsize (missile, '0 0 0', '0 0 0');
setorigin (missile, self.origin + v_forward*8 + '0 0 16');
};
Re: How to make a rocket fly on a spiral trajectory?
some sexy stuff here =)
Re: How to make a rocket fly on a spiral trajectory?
Fraking awesome, especially that it is two separate rockets.
Re: How to make a rocket fly on a spiral trajectory?
Thanks for the code.
Little tweaking of the routine nice to have three rockets going at once.
As in first rocket just fires in a straight line with two other rockets doing a spiral around first rocket.
Lots of crazy ideas are possible.
Little tweaking of the routine nice to have three rockets going at once.
As in first rocket just fires in a straight line with two other rockets doing a spiral around first rocket.
Lots of crazy ideas are possible.
Re: How to make a rocket fly on a spiral trajectory?
would the rockets still spiral if they slow dropped altitude ?