to Booth Main
Getting rid of AutoAim and GetShOrg (Get Shot Origin) tutorial
Sometimes autoaim is nice. And sometimes it just plain gets in the way of getting in a decisive shot. So, here's what we need to do to get rid of autoaim entirely, without using a console variable. Also, we'll add a function to return a proper origin for certain types of projectiles (nails, rockets, etc.)
Open weapons.qc, and right above W_FireAxe add:
// NoAutoAim: Returns your v_forward and nothing else.
vector(entity e) NoAutoAim =
// GetShOrg: Returns a vector based on self.origin + self.view_ofs
// Used for setting actual projectile origins.
vector(float u, float r, float f) GetShOrg =
local vector og;
og = self.origin + self.view_ofs + v_up*u + v_right*r + v_forward*f;
Now, NoAutoAim returns a vector variable from the entity e. makevectors is what fills in the preset variables v_forward, v_right, and v_up.
GetShOrg also returns a vector variable, but is intended for use directly by the calling entity. Variables u, r and f stand for up, right, and forward adjustments relative to your view offset (the player's view offset is what defines where you happen to be looking from, hence why your view isn't from the player's stomach =P )
Now to actually put these to use:
Go down to W_FireShotgun and change this:
dir = aim (self, 100000);
dir = NoAutoAim(self);
Now the regular shotgun won't use autoaim at all. Note that you must do this for the super shotgun, nailgun, super nailgun and rocket launcher as well if you don't want them to use autoaim at all. Also note, that it is possible to code things such that you could toggle autoaim on or off. (Exercise left to reader)
Now, go down to W_FireRocket and change this:
setorigin (missile, self.origin + v_forward*8 + '0 0 16');
setorigin (missile, GetShOrg(0, 0, 8));
Much shorter and nicer no? It does the same thing, and if you want, you can change things around so that the rocket launches not from the center, but from the right or left or even upper sides of the screen. Note that you can use negative values as well with this.
What we learned:
vector and .vectors can only be set by use of a vector value. e.g. '0 0 0', or alternately by using the _x, _y, and _z accesses of said vector. (ex. self.vector_x, self.vector_y, self.vector_z)
makevectors makes magic happen!
AutoAim can be rather evile, and as such can now be dispensed with! For great justice!
GetShOrg is handy for nails and rockets!