Moth game: The sonar

I’m currently working on the reveal/sonar mechanic of Team Kraken’s latest moth game project. The idea is that you are a moth, and your primary means of sensing the environment is by feeling vibrations echoing off of objects around you. The vibrations come from flapping your wings, and if you flap hard enough in a certain direction (by pressing space) it will trigger the sonar. The sonar is a cone of vision stretching out in front of you. Right now this is all represented visually as shown in the image below:

waz0nlh

I implemented the reveal effect using a shader. The shader takes a vision mask texture as input and applies it to anything currently on the screen, keeping it where the mask is white, and fading out to black where the mask does the same. It does this by multiplying the colors of the pixels on screen with the colors of those in the mask. To make the mask dynamic, so it could be white around the player and where the sonar is used, I first made it into a render texture. That way, I could let a special vision camera draw into it. The vision camera’s background is set to black, and it can only see objects that are in the vision layer. The vision layer objects are white sprites with fading edges; the stationary reveal field attached to the player object, and the sonar cone. The whole process of getting the final image on screen is thus as follows:

  1. The vision camera clears the vision mask to black,
  2. then it draws the reveal field and any sonar cones into the mask.
  3. The main camera draws the background and all game objects to the screen.
  4. The vision mask is applied to what is now on the screen.

The problem with how it’s currently being done is that unless the player is using the sonar, everything on the screen except the tiny area around the player is entirely black. This makes the game seem quite dull and void of color and artistic expression during those moments. We have discussed a few different ways to deal with this, including:

  • Not making the unseen area entirely black/invisible. This could be done by setting the background of the vision camera to some dark gray color. You’d still have a hard time seeing what’s there, but it might be less boring to look at.
  • Fading to a darker (and possibly blurred) version of the background instead of fading to black. This would require some changes to the shader, but it would preserve the full effect of the unknown ahead of you.
  • Keeping the sonar cones alive for a longer period of time. Since the sonar cone in its current state is attached to the player, that means it would have to be detatched, so that it stays in place.

About Jacob Lindberg

2016 Programming