Итак, у меня есть этот пистолет, где он вращается в направлении моей мыши по оси x и позиции мыши по оси Y, но проблема ( VIDEO ) в том, что пистолет переворачивается вверх дном. Есть ли способ сделать так, чтобы изображение моего пистолета не перевернулось и не двигалось так же, как мое оружие, обращенное вправо? Как будто пистолет для левой стороны по какой-то причине перевернут, и я вообще не знаю, как это сделать
Изображение пистолета:
![enter image description here](https://i.stack.imgur.com/sMtou.png)
my gun draw(self)
def draw(self,drawX,drawY):
self.rect.topleft = (drawX,drawY)
# the gun's hitbox
# rotating the gun
dx = self.look_at_pos[0] - self.rect.centerx
dy = self.look_at_pos[1] - self.rect.centery
angle = (180/math.pi) * math.atan2(-dy, dx)
gun_size = self.image.get_size()
pivot = (8, gun_size[1]//2)
blitRotate(window, self.image, self.rect.center, pivot, angle)
def lookAt( self, coordinate ):
self.look_at_pos = coordinate
my full gun class
class handgun():
def __init__(self,x,y,height,width,color):
self.x = x
self.y = y
self.height = height
self.width = width
self.color = color
self.rect = pygame.Rect(x,y,height,width)
# LOL THESE IS THE HAND
self.shootsright = pygame.image.load("hands.png")
self.image = self.shootsright
self.rect = self.image.get_rect(center = (self.x, self.y))
self.look_at_pos = (self.x, self.y)
self.isLookingAtPlayer = False
self.look_at_pos = (x,y)
self.hitbox = (self.x + -18, self.y, 46,60)
def draw(self,drawX,drawY):
self.rect.topleft = (drawX,drawY)
# the gun's hitbox
# rotating the gun
dx = self.look_at_pos[0] - self.rect.centerx
dy = self.look_at_pos[1] - self.rect.centery
angle = (180/math.pi) * math.atan2(-dy, dx)
gun_size = self.image.get_size()
pivot = (8, gun_size[1]//2)
blitRotate(window, self.image, self.rect.center, pivot, angle)
def lookAt( self, coordinate ):
self.look_at_pos = coordinate
this is where the rotation happens like how my gun will rotate:
def blitRotate(surf, image, pos, originPos, angle):
# calcaulate the axis aligned bounding box of the rotated image
w, h = image.get_size()
sin_a, cos_a = math.sin(math.radians(angle)), math.cos(math.radians(angle))
min_x, min_y = min([0, sin_a*h, cos_a*w, sin_a*h + cos_a*w]), max([0, sin_a*w, -cos_a*h, sin_a*w - cos_a*h])
# calculate the translation of the pivot
pivot = pygame.math.Vector2(originPos[0], -originPos[1])
pivot_rotate = pivot.rotate(angle)
pivot_move = pivot_rotate - pivot
# calculate the upper left origin of the rotated image
origin = (pos[0] - originPos[0] + min_x - pivot_move[0], pos[1] - originPos[1] - min_y + pivot_move[1])
# get a rotated image
rotated_image = pygame.transform.rotate(image, angle)
# rotate and blit the image
surf.blit(rotated_image, origin)
my full code: скрипт Энди помощь приветствуется, спасибо!