Please note that all screen shots displayed in this blog are works in progress and in no way represent the appearance of the final game. Check out the main site here.

Be sure to follow us everywhere with these links!

Wednesday, June 9, 2010

The problem with stairs...

So yeah, loooooong break between posts... Sorry about that. I've been incredibly ill of late and haven't had much time for work on MSoA. That's about to change, however.

So the main problem for the engine at the moment is collision. Walking around the dungeon, one can't be allowed to walk through walls, or, in the case of a multi-level dungeon, be allowed to fall through the floor.

When it comes to walls, the collision is fairly simple; if a player is standing in north/south facing corridor segment, they are only allowed to walk forward if they are facing north or south. If they are in a corridor segment, it will also only allow them to walk in one direction or the other. So, understandably, this part of the player collision is quite straightforward. Likewise, in-level objects such as tables, etc, can be detected easily with an algorithm something like "player wants to move forward - check in front of player - is there an object there? - if so, do not allow player to move forward - if not, then move player forward in accordance to dungeon segment collision".

So yes, that side of things was working swimmingly, but in MSoA, the dungeons are multi-storey, and thus I had to deal with stairs - ever a problem with me. The main problem when dealing with them is this (and it gets a little hard to explain, so please bear with me): any given staircase has two openings; one at the top and one at the bottom. If you are standing at the top of a staircase and you enter said staircase, you will be going down. If you enter the bottom of a staircase you will be going up. Fairly straightforward. BUT, lets say you divide the staircase into three parts (which the MSoA engine does); part A is the top, part B is the middle and part C is the bottom. If you enter part A, the computer should know that you intend to go DOWN the stairs, and thus move the camera downwards as you walk, making it look like you're walking down the stairs, right? WRONG! That situation is only predicated upon you entering part A of the staircase from OUTSIDE the staircase. If you were to enter part A of the staircase COMING FROM part B of the staircase, technically you should be traveling UPWARDS and not DOWNWARDS.
I warned you it was hard to explain.
Anyway, this COULD be overcome by processing the last section you were in and comparing it to the section you're moving into, however, that would require hard coding data relating to the various sections of the level, and I can't do that because the level isn't being designed by me. It's being designed by the COMPUTER.
So it was a pickle. A very difficult to solve pickle. And while it HAS been a long time since I've done some serious work on the engine, I have actually spent the entire time pondering how to solve this problem.
And, ladies and gentlemen, tonight I managed to solve it. The answer? Sliding collision :)
What's that you ask? An excellent question. Basically, I have thrown together some code that creates invisible platforms in the base of every dungeon segment generated by the computer. Most segments such as corridors, corners, crossroads, etc, simply have a flat square segment covering their floor (invisible to the player, but it's there) and staircases have slanted segments that follow the path that the stairs make in the level's 3D model. Hidden from the player, these invisible platforms act as a sort of guide rail for the player's view, so every time a player enters into a segment, the camera follows the slope of the invisible platform for that segment. Most of the time that platform is totally flat, so the camera just slides along normally, but when entering a staircase, whether it runs up or down, the camera is guided by the invisible platform running JUUUST under the 3D model of the staircase. Since these platforms are only a few polygons each, it doesn't make a big difference in terms of memory usage, and the player can smoothly and easily run up and down stairs (and so can the beasties mwahahahahaaaa)
I have this working in a separate test application at the moment and it works a treat, so now I just need to integrate the code into the game engine proper. Once that's done I'll probably do up a video showing off the new tech.

Anyway, that's enough ranting for me. Good to be back, guys!

Au revoir!

No comments:

Post a Comment