Hilarious Physics in Combo.Zone – Quantum Productions (DevBlog 9/1/16)

My old physics engine was a bit wonky, with the ships not bouncing as they should and moving drastically from “bouncing” to “stable” as a stun-timer ran out.

The new system has inertia from being hit by a rocket applied separately from your ship thrusters to maintain the “bouncy” feel of ricocheting around the stage while offering a bit of control to the player, giving a challenge to control their ship while maintaining the high-speed comedy of collision physics.

Now, inertia and ship thrusters are handled with a theta and magnitude

 

handleCollision(r) {
var angle = r.r * Math.PI / 180.0;
var rr = this.r * Math.PI / 180.0;
var rocketVector = {‘x’ : r.power * Math.cos(angle), ‘y’ : r.power * Math.sin(angle)};
var inertiaVector = {‘x’ : this.magnitude * Math.cos(rr), ‘y’ : this.magnitude * Math.sin(rr)};

var rMass = r.mass;
var shipMass = this.t.mass;

var x = (rMass * rocketVector.x) + (shipMass * inertiaVector.x);
var y = (rMass * rocketVector.y) + (shipMass * inertiaVector.y);
var xDividedByMass = x / (shipMass);
var yDividedByMass = y / (shipMass);

var yRadians = (yDividedByMass * Math.PI / 180);
var xRadians = (xDividedByMass * Math.PI / 180);
var theta = Math.atan( yRadians / xRadians);

theta = theta * 180 / Math.PI;

var hypotenuse = Math.sqrt((xDividedByMass * xDividedByMass) + (yDividedByMass * yDividedByMass));

and so far the game is more fun with these better physics!

Leave a Reply

Your email address will not be published.