This site requires JavaScript, please enable it in your browser!
Greenfoot back
wabuilderman
wabuilderman wrote ...

2016/6/12

Physics in 2D raycasting Engine

wabuilderman wabuilderman

2016/6/12

#
I just published my raycasting game, but the physics I attempted to create don't appear to be working properly. Can someone check me on my code? I believe the problem is occuring in the 'MoveWithPhysics' function that I created. Also, pardon my sloppy coding. Project reference: http://www.greenfoot.org/scenarios/17096
SPower SPower

2016/6/12

#
It's not entirely clear to me what the MoveWithPhysics method is supposed to do. If you could clarify your implementation of a raycaster a little more, that would make it easier to help you (simply because going through stuff like this will take more time than simpler scenarios). I would like to say something about the 'fisheye-effect' apparent in your scenario (that is, a wall that should appear straight looks bulged), it's because you should not use the length of the ray that is cast, but the length of the ray parallel to the camera direction. This is the the dot product of the camera direction and the ray-vector, the first of which would be a unit vector. And although this is a little nitpicking (still done in kindness though), I read in the description of your scenario that Doom used raycasting as well, but this is actually not the case. The way walls are stretched is similar, but while Wolfenstein 3D was a raycaster, Doom isn't. :)
wabuilderman wabuilderman

2016/6/12

#
The 'MoveWithPhysics' function is essentially drawing a line segment between my current location, and the new desired location. If this movement line were to intersect any wall, I want to place the player slightly behind the point of the collision (that way he isn't stuck in the wall). As for the fisheye-effect, thanks for the tip. I will look into that. Also, interesting fact about doom. I hadn't realized that.
You need to login to post a reply.