Reputation: 11
i'm trying to make a circle go towards the way its looking, when i put 0 it goes towards 0 but when i put 90 for some reason it goes towards like 200 or something
import pygame
import math
import random
from random import randint
pygame.init()
screen = pygame.display.set_mode([500, 500])
""""""
def rad_to_offset(radians, offset):
x = math.cos(radians) * offset
y = math.sin(radians) * offset
return [x, y]
X = 250
Y = 250
""""""
clock = pygame.time.Clock()
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
""" if i put 90 it doesnt go towards 90 """
xy = rad_to_offset(90, 1)
X += xy[0]
Y += xy[1]
print(X, Y)
screen.fill((255, 255, 255))
pygame.draw.circle(screen, (0, 0, 255), (X, Y), 20)
pygame.display.flip()
pygame.quit()
Upvotes: 0
Views: 38
Reputation: 210909
The unit of the angle in the trigonometric functions is Radian but not Degree. Use math.radians
to convert from degrees to radians:
def rad_to_offset(degrees, offset):
x = math.cos(math.radians(degrees)) * offset
y = math.sin(math.radians(degrees)) * offset
return [x, y]
Upvotes: 1