Limiting a vector?
Moderator: InsideQC Admins
12 posts
• Page 1 of 1
Limiting a vector?
Using this tutorial: http://inside3d.com/showtutorial.php?id=44 (a modified version anyway), is there a way to limit how much the projectile can alter it's angles when it homes in on an enemy?
IE: the rocket sees a target, but can't do a compete 180 degree turn to get to it, it will only be able to turn a certain amount?
IE: the rocket sees a target, but can't do a compete 180 degree turn to get to it, it will only be able to turn a certain amount?
- DusterdooSmock
- Posts: 170
- Joined: Thu Aug 19, 2010 9:58 pm
Re: Limiting a vector?
Maybe something like this, find in RockThick() :
and change to:
Hmmm on second thought that wouldn't really do what you want, you would need to convert the 'dir' vector to angles and slowly turn the current angles -- which is more tricky
- Code: Select all
self.velocity = dir * 250
and change to:
- Code: Select all
self.velocity = self.velocity + dir * 25
Hmmm on second thought that wouldn't really do what you want, you would need to convert the 'dir' vector to angles and slowly turn the current angles -- which is more tricky
- andrewj
- Posts: 133
- Joined: Mon Aug 30, 2010 3:29 pm
- Location: Australia
Re: Limiting a vector?
andrewj wrote:
- Code: Select all
self.velocity = self.velocity + dir * 25
I gave it a shot anyway, just to see what it would do... For some reason the rockets didn't home in on ANY enemies with that.
- DusterdooSmock
- Posts: 170
- Joined: Thu Aug 19, 2010 9:58 pm
Re: Limiting a vector?
New direction should be the old direction plus some fraction of the current direction to target. This might do it:
I don't know if it's the most efficient way.
- Code: Select all
dir = normalize(normalize(self.velocity) + 0.2*normalize(vtemp - self.origin));
I don't know if it's the most efficient way.
-
qbism - Posts: 1236
- Joined: Thu Nov 04, 2004 5:51 am
Re: Limiting a vector?
qbism wrote:New direction should be the old direction plus some fraction of the current direction to target. This might do it:
- Code: Select all
dir = normalize(normalize(self.velocity) + 0.2*normalize(vtemp - self.origin));
I don't know if it's the most efficient way.
We're getting there.. It works, but for some reason, the rocket either turns to the left or right, it doesn't hit the enemy directly.
- DusterdooSmock
- Posts: 170
- Joined: Thu Aug 19, 2010 9:58 pm
Re: Limiting a vector?
You might want to allow finer adjustments the closer you get to the target.
Wide adjustments the farther out you are, then finer adjustments the closer you get, so by the time you get to the opponent you make sure to hit them,
but the overall angle isn't clearly sharp or jarring.
slowing how often the .think updates would likely be a cheap alternative.
Personally I stole ids homing missile code, and put it on a timer.
It shoots where you aim it for the first 10 quake time units, and only after that does the homing even kick in, at which point i sped it up to 600, giving it a nice sloooow
shot towards then enemy then WHIPOW straight to them. I should also admit i was imitating an effect I saw in a quake mod on youtube. I apologize for not being able to credit the vid, the effect looked much like the mortar in twisted metal 2.
Wide adjustments the farther out you are, then finer adjustments the closer you get, so by the time you get to the opponent you make sure to hit them,
but the overall angle isn't clearly sharp or jarring.
slowing how often the .think updates would likely be a cheap alternative.
Personally I stole ids homing missile code, and put it on a timer.
It shoots where you aim it for the first 10 quake time units, and only after that does the homing even kick in, at which point i sped it up to 600, giving it a nice sloooow
shot towards then enemy then WHIPOW straight to them. I should also admit i was imitating an effect I saw in a quake mod on youtube. I apologize for not being able to credit the vid, the effect looked much like the mortar in twisted metal 2.
-

gnounc - Posts: 424
- Joined: Mon Apr 06, 2009 6:26 am
Re: Limiting a vector?
I have a heat seeker missile in one of my unfinished mods that turns slowly towards the enemy, while accelerating. Here's the code:
- Code: Select all
// =============================================================================
// teleguided missile
// =============================================================================
void() heatSeekerThink =
{
local vector dir, newvel;
dir = normalize((self.enemy.origin + '0 0 8') - self.origin);
self.angles = vectoangles(dir);
newvel= dir * self.count;
self.velocity_x = 0.66 * self.velocity_x + 0.33 * newvel_x;
self.velocity_y = 0.66 * self.velocity_y + 0.33 * newvel_y;
self.velocity_z = 0.66 * self.velocity_z + 0.33 * newvel_z;
if (self.count < 1200)
{
self.count = self.count + 100;
self.think = heatSeekerThink;
self.nextthink = time + 0.25;
}
else
{
self.think = SUB_Remove;
self.nextthink = time + 0.1;
}
};
void() fireHeatSeeker =
{
local entity missile;
local vector dir;
dir = normalize((self.enemy.origin + '0 0 8') - self.origin);
missile = spawn ();
missile.count = 150;
missile.angles = vectoangles(dir);
missile.owner = self;
missile.enemy = self.enemy;
missile.solid = SOLID_BBOX;
missile.movetype = MOVETYPE_FLYMISSILE;
setmodel (missile, "progs/missile.mdl");
setsize (missile, '0 0 0', '0 0 0');
missile.origin = self.origin + '0 0 8';
missile.velocity = dir * missile.count;
missile.touch = T_LavaBallTouch;
missile.think = heatSeekerThink;
missile.nextthink = time + 0.05;
// set rocket duration
missile.attack_finished = time + 5;
};
I know FrikaC made a cgi-bin version of the quakec interpreter once and wrote part of his website in QuakeC
(LordHavoc)
-

frag.machine - Posts: 2090
- Joined: Sat Nov 25, 2006 1:49 pm
Re: Limiting a vector?
frag.machine wrote:I have a heat seeker missile in one of my unfinished mods that turns slowly towards the enemy, while accelerating. Here's the code:
It works, but I've been trying all morning to get it to not accelerate, just slowly change angles, but to no avail..
Basically, all I'm trying to get it to do is something like this:
- establish a maximum angle that the projectile can turn to. (IE can't turn to an angle > this angle, can't turn to an angle < this angle * -1)
- check the angles
- if the angle is past those limits, set it to the maximum that is allowed.
I've tried to do it a few times on my own, but vector math is an area that I am weak in.
- DusterdooSmock
- Posts: 170
- Joined: Thu Aug 19, 2010 9:58 pm
Re: Limiting a vector?
- Code: Select all
self.velocity = normalize(self.velocity);
newVec = self.enemy.origin - self.origin;
newVec = normalize(newVec);
t = time - self.ltime;
self.ltime = time;
percentage = 0.1;
self.velocity = (self.velocity * (1 - percentage) * t) + ( newVec * percentage * t);
self.velocity = normalize(self.velocity);
self.velocity = self.velocity * 600;
self.angles = vectoangles(self.velocity);
will constantly seek at 600 units/sec but will be capped when turning depending on what you set 'percentage' to. higher numbers will turn faster.
- necros
- Posts: 77
- Joined: Thu Dec 16, 2004 10:32 pm
Re: Limiting a vector?
I'm still getting the same results as with the other solutions;
the rocket fires, goes straight, then last minute, it makes a sharp turn, then hits the enemy.
I'm trying to do something like this;
vector newdir;
float maxdir;
maxdir = some number;
if the angles of the newdir are > than the maximum angles allowed (maxdir)
then set the angles of the newdir to the maxdir
if the angles of the newdir are < than the maximum angles allowed * -1
then set the angles of the newdir to maxdir * -1
That way the rocket can't turn more than the game allows it to.
If the shot doesn't hit the enemy because the rocket couldn't turn enough, then the player will have to try again.
the rocket fires, goes straight, then last minute, it makes a sharp turn, then hits the enemy.
I'm trying to do something like this;
vector newdir;
float maxdir;
maxdir = some number;
if the angles of the newdir are > than the maximum angles allowed (maxdir)
then set the angles of the newdir to the maxdir
if the angles of the newdir are < than the maximum angles allowed * -1
then set the angles of the newdir to maxdir * -1
That way the rocket can't turn more than the game allows it to.
If the shot doesn't hit the enemy because the rocket couldn't turn enough, then the player will have to try again.
- DusterdooSmock
- Posts: 170
- Joined: Thu Aug 19, 2010 9:58 pm
Re: Limiting a vector?
qbism wrote:Have you looked at vore ball code?
Just took a look at it after I read this, didn't see anything new except for a change in the ball's velocity based on the skill..
EDIT: Anyone have any ideas on doing this? I still haven't got it working..
- DusterdooSmock
- Posts: 170
- Joined: Thu Aug 19, 2010 9:58 pm
12 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 1 guest