Time to cast some rays

Next on the list: raycasting! Much to my suprise, it wasn’t that difficult. So I won’t be ranting today. I’m so glad it all worked out nicely, I expected this to be a very difficult task. Not so difficult that I couldn’t finish it, but I was kind of worried about the time it would take me to finish it. To be honest, testing the system I coded for raycasting was harder than actually coding the system itself, haha. At some point I had to hop back and forth between on-screen- and world-coordinates and messed up a few lines. That, combined with the fact that sometimes my brain switches around variable names (for example l1x turns into x1) gave some unexpected results. After an hour of explaining how the code works to my rubber duck and making a special function for converting on-screen- and world-coordinates the prototype worked.

“A picture says more than a thousand words.” They say. Well, to lift the word count of this blog a bit, here are some “pictures”.

The red line represents the ray. The blue cross indicates the point of collision.

The red line represents the ray. The blue cross indicates the point of collision.

It also works with the borders of the level!

It also works with the borders of the level!

And it indicates where the collision occurred first. This is important, because there occurred two collisions here: one with the border and one with a wall.

And it indicates where the collision occurred first. This is important, because there occurred two collisions here: one with the border and one with a wall.

It’s nice that implementing raycasting was really easy, because I can now finally move on to the interesting part of my project: the AI! The AI needs raycasting for their field of view. Later on I will (hopefully) also be using the raycasting system to display the field of view of the guards, and also maybe the field of view of the player. But I’ll only be able to implement that if I have enough time. So we’ll see.

– Bob

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: