I’m making a raycaster (like doom / wolfenstein) for my programming class in a (basically) dumbed down python (CMU CS Academy), I’ve managed to get the main raycaster to work, but when trying to implement the entity sprites, they teleport around the screen instead of displaying where the should be.
(“m.” is the “math.” since I used “import math as m”)
.gif of issue: https://drive.google.com/file/d/1pZvUxjHU7V4LD6hGaFsUSGZOlxLXsNXu/view
def drawEntity(entity):
dir = plr.rotateAngle # camera directoin
x = (entity.centerX - plr.centerX) # entity's relative position to player
y = (entity.centerY - plr.centerY)
# not used # # dis = m.sqrt((plr.centerX - entity.centerX)**2 + (plr.centerY - entity.centerY)**2)
vx = x * m.cos(dir) - y * m.sin(dir) # is supposed to rotate the location of the sprite
vy = x * m.sin(dir) + y * m.cos(dir) # but doesnt seem to work
if vy > 0:
sprite = Image(entities.animations[m.floor(entity.animation)], 200, 200)
height = 30 * app.maxDistance / vy # where app.maxDistance = 200 / m.tan(45)
sprite.width, sprite.height = abs(320 * height * 0.01), abs(320 * height * 0.01) # 320 is the image's width / height
sprite.centerX, sprite.centerY = vx * (app.maxDistance / vy)+200, 200 # x-pos is messed up some how
sprites.add(sprite) # draws sprite
the program display uses x/y coords 0-400
I was expecting the sprite to display the correct position in 3D space when the camera rotates
instead, when the camera rotates, the sprite teleports
I think it might have something to do with the ‘vx’ and ‘vy’ variables
VPexMC is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.