-2

I imported math. whenever I try to use it and run the code, I get this error:

AttributeError: module 'pygame.math' has no attribute 'sin'

This is my code:

def move(steps,):
    try_move(steps * math.sin(direction),0)
    try_move(0,steps * math.cos(direction) )
2
  • Please update your question with your import statement relating to math Commented Feb 19 at 9:33
  • I think in pygame you can create pygame.math.Vector2(steps) and later use rotate(direction) to get the same values without using steps*sin() and steps*cos() Commented Feb 24 at 2:13

1 Answer 1

6

It doesn't look like you imported the builtin math module, but rather pygame.math (which doesn't have a sin function).

You should import math and not from pygame import math:

import math

math.sin(direction)

Your error is quite clear about it, notice the pygame.math:

AttributeError: module 'pygame.math' has no attribute 'sin'
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.