1
1
import math
2
2
from typing import Union
3
3
4
+ from rlbot .utils .structures .game_data_struct import Vector3
5
+
4
6
5
- # This is a helper class for vector math. You can extend it or delete if you want.
6
7
class Vec3 :
7
8
"""
8
9
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:
21
22
'z'
22
23
]
23
24
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 ):
25
26
"""
26
27
Create a new Vec3. The x component can alternatively be another vector with an x, y, and z component, in which
27
28
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):
74
75
"""Returns a new Vec3 that equals this Vec3 but projected onto the ground plane. I.e. where z=0."""
75
76
return Vec3 (self .x , self .y , 0 )
76
77
77
- @property
78
78
def length (self ):
79
79
"""Returns the length of the vector. Also called magnitude and norm."""
80
80
return math .sqrt (self .x ** 2 + self .y ** 2 + self .z ** 2 )
81
81
82
82
def dist (self , other : 'Vec3' ) -> float :
83
83
"""Returns the distance between this vector and another vector using pythagoras."""
84
- return (self - other ).length
84
+ return (self - other ).length ()
85
85
86
- @property
87
86
def normalized (self ):
88
87
"""Returns a vector with the same direction but a length of one."""
89
- return self / self .length
88
+ return self / self .length ()
90
89
91
90
def rescale (self , new_len : float ) -> 'Vec3' :
92
91
"""Returns a vector with the same direction but a different length."""
93
- return new_len * self .normalized
92
+ return new_len * self .normalized ()
94
93
95
94
def dot (self , other : 'Vec3' ) -> float :
96
95
"""Returns the dot product."""
@@ -106,5 +105,5 @@ def cross(self, other: 'Vec3') -> 'Vec3':
106
105
107
106
def ang_to (self , ideal : 'Vec3' ) -> float :
108
107
"""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 () )
110
109
return math .acos (cos_ang )
0 commit comments