0

I am creating a game and I need to provide rect.x with a decimal number to control the players speed. But my player never ends up moving when going below 1. Is there anyway I can assign a decimal number to rect.x? I am using python 3.10.4 with spyder IDE on a windows 10 home computer. Any answer is very much appreciated.

Code:

vel = 0.5
userInput = pygame.key.get_pressed()
if userInput[pygame.K_LEFT]:
    rect.x -= vel
if userInput[pygame.K_RIGHT]:
    rect.x += vel
if userInput[pygame.K_UP]:
    rect.y -= vel
if userInput[pygame.K_DOWN]:
    rect.y += vel
OddsOver1
  • 13
  • 4
  • You can not. You must use separate variables or attributes that store the position of the rectangle and synchronize it with the position of the rectangle. See [Pygame doesn't let me use float for rect.move, but I need it](https://stackoverflow.com/questions/63468413/pygame-doesnt-let-me-use-float-for-rect-move-but-i-need-it/63468637#63468637) – Rabbid76 Apr 10 '22 at 13:05

0 Answers0