• Register
Quake c - Velocity

Move and rotate quake entities with velocity. --

Posted by on - Intermediate Server Side Coding

Velocity is the rate of change of the position of an object, equivalent to a specification of its speed and direction of motion: En.wikipedia.org
The scalar absolute value (magnitude) of velocity is called "speed".

// defs.qc
.vector avelocity;
.vector velocity;
".velocity" defines one of the per-entity variables the quake engine works upon directly.
This is one of the most important concepts in the game, and it receives very little coverage in programming context. One of the easiest ways to move something in the game is to set velocity and movetype.

".avelocity" is just a scalar value that defines rotation speed (and sign for direction) about an axis - x, y, z, accordingly. ".avelocity" has no typical use as a standard vector.

When gibs and grenades flip around as they fly along, this is done by setting ".avelocity":

newmis.avelocity = '300 300 300'; // in W_FireGrenade

Using ".velocity" - code from "void () W_FireRocket" in weapons.qc:

// self is the rocket firing player, newmis is the missile entity

makevectors (self.v_angle); // put gun aim into 1 unit (normal) angles v_forward, v_up, and v_right
newmis.velocity = aim (self,1000); // a builtin that handles autoaim if turned on// with no autoaim, aim is equivalent to:
// newmis.velocity = v_forward; // 1 unit vector from aim pointer self.v_angle - where your gun is aimed

newmis.velocity = newmis.velocity * 1000;
// if you want to determine the speed from a velocity:
// float speed;
// speed = vlen(self.velocity);

newmis.angles = vectoangles (newmis.velocity); // point the rocket tip where velocity vector is going
".velocity" is a vector - it defines a direction (v_forward) and a magnitude (1000). "1000" is the "speed" of the entity.

The quake engine will now move the missile entity in the indicated direction at that rate of speed.
To make a homing missile: design a missile think function that adjusts the missiles velocity and speed to track a target.
Note: homing missiles typically move slower than standard rockets.

Thanks for keeping the Quake info flowing!

Your welcome. :-) Sharing the knowledge gives me more motivation to work on quake stuff.

Reply Good karma+1 vote

Quake C manual ver 3.4 entries for movement:

6.2 Definition of entity fields

Movement in 3D

vector velocity; // = 'speed_x speed_y speed_z'
vector avelocity; // = 'pitch_speed yaw_speed 0', angle velocity
vector punchangle; // temp angle adjust from damage or recoil
float movetype; // type of movement
float yaw_speed; // rotation speed
float solid; // tell if entity can block the movements.

Reply Good karma+1 vote