My apologies if this is really obvious but I honestly have no clue what’s happening.
I call a function with a list entry as one of the parameters. Inside the function, I modify the values because I need to, and somehow the original list ends up being changed even though never referenced?
objects = [[0, [5, 0.3, 1.2], 1, (255, 0, 0)], [0, [3, 0, -1.5], 1, (0, 0, 255)]]
"""Obj Index:
[type, pos, size, colour]
0: Cube"""
running = True
FOV = 70
camerapos = [0, 0, 0]
while running:
print(camerapos)
screen.fill((0, 0, 0))
for event in pygame.event.get():
if event.type == pygame.QUIT: running = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_w:
camerapos[0] += 0.02
if event.key == pygame.K_s:
camerapos[0] -= 0.02
if event.key == pygame.K_a:
camerapos[2] -= 0.02
if event.key == pygame.K_d:
camerapos[2] += 0.02
for i in objects:
drawShape(i, FOV, screen, camerapos)
def drawShape(data, FOV, screen, camerapos):
if data[0] == 0:
for i in range(len(data[1])):
data[1][i] -= camerapos[i]
When I press any of WASD, the camera starts moving and doesnt stop when I lift my finger. Pressing the key again just makes it speed up, pressing the opposite key slows it down.
Also how do I make it so that I can hold a key down to move? It used to work like this but now doesn’t and I cant find anything on it.