![enter image description here](https://i.stack.imgur.com/k7M3R.png)
I am having an issue where my bullets dont look like they are coming out of my gun they look like they are coming out of the players body ВИДЕО как вы можете видеть на видео, он стреляет где-то в другом месте, или это пистолет, то же самое для левой стороны, он хорошо стреляет, поднимаясь вверх, но стреляет плохо, когда падает ВИДЕО
![enter image description here](https://i.stack.imgur.com/14cFJ.png)
I tried angeling my gun to 120 but what happens is everything good works for the right side not for the left side ВИДЕО как вы видите, это просто сбои
мой класс снаряда
class projectile(object):
def __init__(self, x, y, dirx, diry, color):
self.x = x
self.y = y
self.dirx = dirx
self.diry = diry
self.slash = pygame.image.load("round.png")
self.slash = pygame.transform.scale(self.slash,(self.slash.get_width()//2,self.slash.get_height()//2))
self.rect = self.slash.get_rect()
self.rect.topleft = ( self.x, self.y )
self.speed = 18
self.color = color
self.hitbox = (self.x + -18, self.y, 46,60)
как мой снаряды добавляют
if event.type == pygame.MOUSEBUTTONDOWN:
# this is for the bullets
if len(bullets) < 3:
if box1.health > 25:
mousex, mousey = pygame.mouse.get_pos()
playerman.isJump = True
start_x, start_y = playerman.x - 30, playerman.y - 65
mouse_x, mouse_y = event.pos
dir_x, dir_y = mouse_x - start_x, mouse_y - start_y
distance = math.sqrt(dir_x**2 + dir_y**2)
if distance > 0:
new_bullet = projectile(start_x, start_y, dir_x/distance, dir_y/distance, (0,0,0))
bullets.append(new_bullet)
# this is displaying the bullets for the player
for bullet in bullets[:]:
bullet.move()
if bullet.x < 0 or bullet.x > 900 or bullet.y < 0 or bullet.y > 900:
bullets.pop(bullets.index(bullet))
def draw(self,drawX,drawY):
self.rect.topleft = (drawX,drawY)
# the guns hitbox
# rotatiing the gun
dx = self.look_at_pos[0] - self.rect.centerx
dy = self.look_at_pos[1] - self.rect.centery
angle = (190/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)
if((angle > 90 or angle < -90) and self.gunDirection != "left"):
self.gunDirection = "left"
self.image = pygame.transform.flip(self.image, False, True)
if((angle < 90 and angle > -90) and self.gunDirection != "right"):
self.gunDirection = "right"
self.image = pygame.transform.flip(self.image, False, True)
мой полный класс оружия
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)
self.gunDirection = "right"
def draw(self,drawX,drawY):
self.rect.topleft = (drawX,drawY)
# the guns hitbox
# rotatiing the gun
dx = self.look_at_pos[0] - self.rect.centerx
dy = self.look_at_pos[1] - self.rect.centery
angle = (120/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)
if((angle > 90 or angle < -90) and self.gunDirection != "left"):
self.gunDirection = "left"
self.image = pygame.transform.flip(self.image, False, True)
if((angle < 90 and angle > -90) and self.gunDirection != "right"):
self.gunDirection = "right"
self.image = pygame.transform.flip(self.image, False, True)
def lookAt( self, coordinate ):
self.look_at_pos = coordinate
white = (255,255,255)
handgun1 = handgun(300,300,10,10,white)
how my images are blitted
```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)
Я думаю, что я пытаюсь сказать, как я могу заставить мое оружие вращаться точно на моем позиционирование мыши без проблем
мой полный код скрипт