implementation of angle fixer + better print
This commit is contained in:
parent
5bd02e8afa
commit
d32b733f2c
1 changed files with 35 additions and 13 deletions
48
utils.py
48
utils.py
|
@ -11,6 +11,10 @@ class Vec:
|
||||||
self.z = 0
|
self.z = 0
|
||||||
|
|
||||||
def new(self, x: int | float, y: int | float | None, z: int | float | None) -> None:
|
def new(self, x: int | float, y: int | float | None, z: int | float | None) -> None:
|
||||||
|
"""Change values of Vector"""
|
||||||
|
if y == None:
|
||||||
|
raise TypeError
|
||||||
|
|
||||||
# Determine type of class
|
# Determine type of class
|
||||||
self.type = int
|
self.type = int
|
||||||
if type(x) == float:
|
if type(x) == float:
|
||||||
|
@ -19,13 +23,6 @@ class Vec:
|
||||||
# Verify other type
|
# Verify other type
|
||||||
if type(y) != self.type:
|
if type(y) != self.type:
|
||||||
raise TypeError
|
raise TypeError
|
||||||
if y != None:
|
|
||||||
if type(y) != self.type:
|
|
||||||
raise TypeError
|
|
||||||
|
|
||||||
# At this point, they can't be None
|
|
||||||
if y == None:
|
|
||||||
raise TypeError
|
|
||||||
|
|
||||||
self.x = self.type(x)
|
self.x = self.type(x)
|
||||||
self.y = self.type(y)
|
self.y = self.type(y)
|
||||||
|
@ -35,6 +32,15 @@ class Vec:
|
||||||
else:
|
else:
|
||||||
self.z = self.type(z)
|
self.z = self.type(z)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
max_precision = 3
|
||||||
|
|
||||||
|
x = round(self.x, max_precision)
|
||||||
|
y = round(self.y, max_precision)
|
||||||
|
z = None if self.z == None else round(self.z, max_precision)
|
||||||
|
|
||||||
|
return f"{self.__class__.__name__}({x}, {y}{'' if z == None else f', {z}'})"
|
||||||
|
|
||||||
def plus(self, other: 'Vec') -> 'Vec':
|
def plus(self, other: 'Vec') -> 'Vec':
|
||||||
x = self.x + other.x
|
x = self.x + other.x
|
||||||
y = self.y + other.y
|
y = self.y + other.y
|
||||||
|
@ -53,14 +59,14 @@ class Vec:
|
||||||
|
|
||||||
return Vec(x, y, self.z - other.z)
|
return Vec(x, y, self.z - other.z)
|
||||||
|
|
||||||
def div(self, val: float) -> 'Vec':
|
def div(self, factor: float) -> 'Vec':
|
||||||
x = self.x / val
|
x = self.x / factor
|
||||||
y = self.y / val
|
y = self.y / factor
|
||||||
|
|
||||||
if self.z == None:
|
if self.z == None:
|
||||||
return Vec(x, y)
|
return Vec(x, y)
|
||||||
|
|
||||||
return Vec(x, y, self.z / val)
|
return Vec(x, y, self.z / factor)
|
||||||
|
|
||||||
def to_angle(self):
|
def to_angle(self):
|
||||||
if self.z == None:
|
if self.z == None:
|
||||||
|
@ -70,8 +76,7 @@ class Vec:
|
||||||
|
|
||||||
return Vec(
|
return Vec(
|
||||||
atan2(-self.z, hypot(self.x, self.y)) * deg_to_rad,
|
atan2(-self.z, hypot(self.x, self.y)) * deg_to_rad,
|
||||||
atan2(self.y, self.x) * deg_to_rad,
|
atan2(self.y, self.x) * deg_to_rad
|
||||||
0
|
|
||||||
)
|
)
|
||||||
|
|
||||||
def is_zero(self):
|
def is_zero(self):
|
||||||
|
@ -85,3 +90,20 @@ class Vec:
|
||||||
def calculate_angle(local_pos: Vec, ennemy_pos: Vec, angles: Vec) -> Vec:
|
def calculate_angle(local_pos: Vec, ennemy_pos: Vec, angles: Vec) -> Vec:
|
||||||
"""Angle calculation for aimbot"""
|
"""Angle calculation for aimbot"""
|
||||||
return ((ennemy_pos.minus(local_pos).to_angle().minus(angles)))
|
return ((ennemy_pos.minus(local_pos).to_angle().minus(angles)))
|
||||||
|
|
||||||
|
|
||||||
|
def angle_fixer(angle: Vec) -> Vec:
|
||||||
|
"""Force the angle to respect game limitation"""
|
||||||
|
# Limit of pitch in game is ]-89; 180[
|
||||||
|
if angle.x > 89.:
|
||||||
|
angle.x = 89.
|
||||||
|
if angle.x < -89.:
|
||||||
|
angle.x = -89
|
||||||
|
|
||||||
|
# Limit of yaw in game is ]-180; 360[
|
||||||
|
while (angle.y > 180.):
|
||||||
|
angle.y -= 360.
|
||||||
|
while (angle.y < -180.):
|
||||||
|
angle.y += 360.
|
||||||
|
|
||||||
|
return angle
|
||||||
|
|
Reference in a new issue