What goes down must come back up! With the new gravity cube, that almost makes sense. To solve this problem, I called my younger brother, who happens to be an mechanical engineer at GORE. I’ll reference his skills later in the post.
I thought it would be fun to let the player control the world gravity, but I wasn’t sure how to do this. I did more research on the game’s 2D engine MatterJS, and discovered that the world gravity vector can easily be updated. If you change the gravity “x” value from zero to 1.0, you will slide to the right, and if you set it to -1.0, you will slide left. With this option, I could change the gravitation direction based on the angle of the cube… but that was going to require math. Thankfully I had a mathematician available.
For the nerdy, here is the solution my brother found:
var pi = Math.PI; var degrees = -angle * (180/pi); var x = Math.cos((90 - degrees) * (pi / 180)); var y = Math.sin((90 - degrees) * (pi / 180));
This allows the world gravity to inherit the angle of the cube, that’s pretty neat hu?!