(EDIT: The rotation doesn't matter too much to me anymore - just the movement. I am still curious and would love to know how to do the rotation however.)
def angle_between(p1, p2):
ang1 = np.arctan2(*p1[::-1])
ang2 = np.arctan2(*p2[::-1])
return (ang1 - ang2) % (2 * np.pi)
class Minion: # Shape: Triangle
def __init__(self):
self.rotation = 0
self.position = (200,200)
self.radius = 50
self.vertices = ((1,1), (10,10), (1,10))
def determine_vertices(self):
x = self.position[0]
y = self.position[1]
target_pos = pygame.mouse.get_pos()
x2 = target_pos[0]
y2 = target_pos[1]
# Will start off pointing to the right (pre-rotation)
vertex_A = (x + self.radius, y)
vertex_B = (x + (cos(2*pi/3))*self.radius, y + (sin(2*pi/3))*self.radius)
vertex_C = (x + (cos(4*pi/3))*self.radius, y + (sin(4*pi/3))*self.radius)
self.vertices = (vertex_A,vertex_B,vertex_C) # NOT YET ROTATED
# Now let's find the angle between my location and the target location
self.rotation = angle_between((x,y),(x2,y2))
# Here is where I am stuck
Okay, so I have found the location of my vertices before they are rotated, and have also found the angle (in radians) in which I want to rotate it towards. Here are the links I've looked at:
Didn't understand / know how to convert to my code
Graph data instead of raw data
EDIT: I have changed my vertex formulas to rotate but they rotate the wrong direction and way too fast. I have no clue why. Here is the code:
vertex_A = (x + (cos(self.rotation))*self.radius, y + (sin(self.rotation))*self.radius)
vertex_B = (x + (cos((2*pi/3) + self.rotation))*self.radius, y + (sin((2*pi/3) + self.rotation))*self.radius)
vertex_C = (x + (cos((4*pi/3) + self.rotation))*self.radius, y + (sin((4*pi/3) + self.rotation))*self.radius)