so I am making a game where the movement involves the player always moving towards the mouse. unfortunately, I have no idea how to do either of these things, but the most important one right now is rotating the image towards the mouse. please help?
Asked
Active
Viewed 22 times
-2
-
1You need to bring the code with what you have already tried so that we can help you, ask for a complete code so there is no way to help, you will only receive negative votes, it is better to delete the question and create a new one with the code and your failed attempts . – Digital Farmer May 10 '22 at 15:56
-
i have not done any code. as i have stated, i have no idea where to start – 2wen May 10 '22 at 16:06
1 Answers
0
I have solved this issue. turns out, i need to use some trig.
self.x += Pl_NPC.speed * cos(self.angle * pi / 180)
self.y -= Pl_NPC.speed * sin(self.angle * pi / 180)
for the movement
self.mouseposx, self.mouseposy = pygame.mouse.get_pos()
mouse_x, mouse_y = pygame.mouse.get_pos()
rel_x, rel_y = mouse_x - self.x, mouse_y - self.y-43
angle = (180 / pi) * -atan2(rel_y, rel_x)
self.img = pygame.transform.rotate(self.orgimg, int(angle) + -90)
self.rect = self.img.get_rect(center=self.pos)
self.angle = int(angle)
for the rotation (this found on the internet)
2wen
- 41
- 9