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

Difference between revisions of "vectoyaw"

From Quake Wiki

(Created page with "====Syntax:==== <code>float vectoyaw(vector vec)</code> Converts a directional vector into a yaw angle (only the _y component of an angles set) ====Parameters:==== :<code>vec...")
 
Line 1: Line 1:
====Syntax:====
+
''float'' '''vectoyaw'''(''vector'' vec)
<code>float vectoyaw(vector vec)</code>
 
  
Converts a directional vector into a yaw angle (only the _y component of an angles set)
+
== Usage ==
====Parameters:====
+
Gets the arc tangent of the vector's x and y values. This is equivalent to <code>atan2</code> in other programming languages.
:<code>vec</code> - The vector to convert
 
====Returns:====
 
:The yaw angle equivalent of the vector
 
  
 +
=== Parameters ===
 +
*''vec''
 +
:Stores the x and y arguments to pass to <code>atan2</code>. The z value does nothing.
 +
 +
=== Return ===
 +
The angle of the x and y components of the vector. Can be a value in the range [0, 360).
 +
 +
== Example ==
 +
// Checks to see if the monster's enemy is in front of them before attacking.
 +
float yawTo = vectoyaw(self.enemy.origin - self.origin);
 +
 +
float delta = anglemod(self.angles.y - yawTo);
 +
if (delta > 45 && delta < 315)
 +
    return;
  
 
[[Category:QuakeC Function]]
 
[[Category:QuakeC Function]]

Revision as of 12:24, 31 July 2023

float vectoyaw(vector vec)

Usage

Gets the arc tangent of the vector's x and y values. This is equivalent to atan2 in other programming languages.

Parameters

  • vec
Stores the x and y arguments to pass to atan2. The z value does nothing.

Return

The angle of the x and y components of the vector. Can be a value in the range [0, 360).

Example

// Checks to see if the monster's enemy is in front of them before attacking.
float yawTo = vectoyaw(self.enemy.origin - self.origin);

float delta = anglemod(self.angles.y - yawTo);
if (delta > 45 && delta < 315)
    return;