Hosting and domain costs until October 2024 have been generously sponsored by dumptruck_ds. Thank you!

Difference between revisions of "normalize"

From Quake Wiki

(Created page with "====Syntax:==== <code>vector normalize(vector vec)</code> This function normalizes a vector. ====Parameters:==== :<code>vec</code> - The vector to normalize ====Returns:==== ...")
 
 
Line 1: Line 1:
====Syntax:====
+
''vector'' '''normalize'''(''vector'' vec)
<code>vector normalize(vector vec)</code>
 
  
This function normalizes a vector.
+
== Usage ==
====Parameters:====
+
Turns a vector into a unit vector (unit vectors have a length of 1). This is useful if you need to scale in a given direction e.g. when firing a missile at a target.
:<code>vec</code> - The vector to normalize
 
====Returns:====
 
:An identical vector as <code>vec</code> but with length of 1.
 
  
 +
=== Parameters ===
 +
*''vec''
 +
:The vector to turn into a unit vector.
 +
 +
=== Return ===
 +
The passed vector as a unit vector.
 +
 +
== Example ==
 +
// Aim a missile at a monster's enemy with a speed of 512 map units/second
 +
vector direction = normalize(self.enemy.origin - self.origin);
 +
missile.velocity = direction * 512;
  
 
[[Category:QuakeC Function]]
 
[[Category:QuakeC Function]]

Latest revision as of 11:59, 31 July 2023

vector normalize(vector vec)

Usage[edit]

Turns a vector into a unit vector (unit vectors have a length of 1). This is useful if you need to scale in a given direction e.g. when firing a missile at a target.

Parameters[edit]

  • vec
The vector to turn into a unit vector.

Return[edit]

The passed vector as a unit vector.

Example[edit]

// Aim a missile at a monster's enemy with a speed of 512 map units/second
vector direction = normalize(self.enemy.origin - self.origin);
missile.velocity = direction * 512;