Drawing sprites in a raycast

So I made a raycaster
https://snap.berkeley.edu/snap/snap.html#present:Username=cookieclickerer33&ProjectName=Actually%20raycaster

But I’m somewhat clueless on drawing sprites
Does anyone have at least somewhere to start?

Based off my experience, I usually try to get a specific ray to render the sprite off of to allow it to get effected by the camera movement. Try to use a list maybe to store data to do something similar.

The only idea I have is recording where the sprite was found on a ray, but to do that I would need to get a ray to hit the printed exact position and I think it would be too percice in order to hit it

I’m gonna try something that might work

Okay I got a system that kinda works, I just don’t know how to apply the lens correction to it (if that’s why it’s offset from its position the more you turn)
https://snap.berkeley.edu/snap/snap.html#present:Username=cookieclickerer33&ProjectName=Actually%20raycaster

Do you have any idea on how to do that?

The code does this:

If a ray hits the object then it’s recorded in a second list of trues and falses
Then the center of the trues is found and then the position the trues start at is added to the center value to properly record it
When the screen draws if the current ray being drawn is equal to that value then the display sprite travels to the x position of the drawing sprite
The sprite then sets it’s size to how far the object is from the player (using an inverse map so it gets smaller as the distance gets bigger)

In order to correct the position I’d need to apply the same correction to the ray length as well as storing the sprites offset from its normal rotation and then use the correction algorithm
This is something that would take alot of work for someone of my expertise but would probably be easier for you

So I made it go to the first instance of true instead of the middle
That should make it okay

I figured it out

You have to run the code to draw the sprite after you draw the background

And now I have to figure out how to make the scaling work

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.