Alien Blitz 3d: accelerometer, optimization

Accelerometer

I’ve change a bit the way the accelerometer is used, and I love it!

Basically:

  • There are 2 vectors storing the accelerometer value
    • One is the average of last 5 seconds (around 5 seconds)
    • The other is the average of last second (around…)
  • The 5 seconds average is used as the reference, considered as “stable” device, so even if you change position the in-game camera will be stable in this position (after a few seconds)
  • The difference between the two vectors is used to move the camera:
    • The camera position is moved behind the player
    • The camera “look at” position is moved in front of the player

I really like that, even if you are shaking it doesn’t move that much in the game, and if you decide to change position it won’t matter, the player does not have to hold the device in a specific position, it will adapt.

Of course this can be disabled in the options.

Technically getting a correct average is very simple, here is some pseudo code

average.xyz = average.xyz * (1 - delta) + accelerometer.xyz * delta;

For a 5 seconds average @ 30 fps then delta=1/(30*5)

Here is the stable view:

2014-06-23 13.25.07

And without moving the player, just turning the device, here is another view (to see what is above):

2014-06-23 13.25.26

 

Optimization

Continuing optimization but this time trying to increase FPS (I can’t do anything better with loading time at the moment). I’ve mainly optimized shaders, gaining a few FPS.

The game is still not really “playable” on my iPod, it is running at around 20fps on an medium level… But it is enough to test (it is still testable above 15fps). 3d on iOs will be for iPhone 5 or more.

Comments are closed.