Asylum Dev Diary 50 – Angled shadows

One aspect that the first floor has is that all of the walls are either horizontal or vertical. However, when I set about designing the reception floor I wanted to have an angled wall that leads down to a glass door (front of the building). I assumed that this wasn’t going to be a problem and created the new wall pieces only to find that the shadows were not rotating to the angle, they seemed to be showing as horizontal shadows.

On further investigation, I discovered that the shadow caster was using the sprites bounding box and not the sprites shape. The bounding box is the box that encapsulates the entire sprite and this expands depending on its rotation:

In this rather small illustration (oops), the bounding box is shown as a black outline. So you can see that when the rectangle is at zero degrees the box outlines perfectly, however when it is rotated the bounding area expands. And so when it came to the shadow caster using the bounding box rather than a thin 45-degree wall shadow I got a very large box shadow.

Fortunately, the shadow casting functions include a slightly more complicated routine for setting up a rectangular shadow that can be set to any width, height and angle – but these parameters have to be set manually instead of just passing the sprite. As the previous walls are all working properly I decided to leave them alone and create a new shadow caster object for these special occasions. The upside to the new shadow object is that they can be at any angle – something I will no doubt use later on.

I am going to go back to my other shadow caster, the one that handles environmental objects like chairs and tables, and update that one so that it uses this alternative more reliable method as I think there are a couple of instances where the shadow is displaying exactly as it should.