11import math
22from typing import Union
33
4+ from rlbot .utils .structures .game_data_struct import Vector3
5+
46
5- # This is a helper class for vector math. You can extend it or delete if you want.
67class Vec3 :
78 """
89 This class should provide you with all the basic vector operations that you need, but feel free to extend its
@@ -21,7 +22,7 @@ class Vec3:
2122 'z'
2223 ]
2324
24- def __init__ (self , x : Union [float , 'Vec3' ]= 0 , y : float = 0 , z : float = 0 ):
25+ def __init__ (self , x : Union [float , 'Vec3' , 'Vector3' ]= 0 , y : float = 0 , z : float = 0 ):
2526 """
2627 Create a new Vec3. The x component can alternatively be another vector with an x, y, and z component, in which
2728 case the created vector is a copy of the given vector and the y and z parameter is ignored. Examples:
@@ -74,23 +75,21 @@ def flat(self):
7475 """Returns a new Vec3 that equals this Vec3 but projected onto the ground plane. I.e. where z=0."""
7576 return Vec3 (self .x , self .y , 0 )
7677
77- @property
7878 def length (self ):
7979 """Returns the length of the vector. Also called magnitude and norm."""
8080 return math .sqrt (self .x ** 2 + self .y ** 2 + self .z ** 2 )
8181
8282 def dist (self , other : 'Vec3' ) -> float :
8383 """Returns the distance between this vector and another vector using pythagoras."""
84- return (self - other ).length
84+ return (self - other ).length ()
8585
86- @property
8786 def normalized (self ):
8887 """Returns a vector with the same direction but a length of one."""
89- return self / self .length
88+ return self / self .length ()
9089
9190 def rescale (self , new_len : float ) -> 'Vec3' :
9291 """Returns a vector with the same direction but a different length."""
93- return new_len * self .normalized
92+ return new_len * self .normalized ()
9493
9594 def dot (self , other : 'Vec3' ) -> float :
9695 """Returns the dot product."""
@@ -106,5 +105,5 @@ def cross(self, other: 'Vec3') -> 'Vec3':
106105
107106 def ang_to (self , ideal : 'Vec3' ) -> float :
108107 """Returns the angle to the ideal vector. Angle will be between 0 and pi."""
109- cos_ang = self .dot (ideal ) / (self .length * ideal .length )
108+ cos_ang = self .dot (ideal ) / (self .length () * ideal .length () )
110109 return math .acos (cos_ang )
0 commit comments