function Player(x, y, gravity, level) {
    this.pos = new Vec2(x, y);
    this.vel = new Vec2(0, 0);
    this.gravity = gravity;
    this.pan = new Vec2(x, y);
    this.angle = gravity;
    this.level = level;
    this.drawSize = 18;
    this.size = 20;
};

Player.prototype.view = function() {
    ctx.translate(width * 0.5, height * 0.5);
    ctx.rotate(-this.angle);
    ctx.translate(-this.pan.x, -this.pan.y);
};

Player.prototype.draw = function() {
    ctx.beginPath();
    ctx.arc(this.pos.x, this.pos.y, this.drawSize, 0, 2 * Math.PI);
    ctx.fill();
};

Player.prototype.update = function() {
    this.pan.sub(this.pos);
    this.pan.mult(0.8);
    this.pan.add(this.pos);
    var angleDiff = (this.gravity - this.angle);
    while(angleDiff < -Math.PI) {
        angleDiff += Math.PI * 2;
        this.angle -= Math.PI * 2;
    }
    while(angleDiff > Math.PI) {
        angleDiff -= Math.PI * 2;
        this.angle += Math.PI * 2;
    }
    this.angle += angleDiff * 0.05;
    var gravity = new Vec2(0, 0.2);
    gravity.rotate(this.gravity);
    var side = gravity.get();
    side.rotate(Math.PI * 0.5);
    this.pos.add(this.vel);
    this.vel.add(gravity);
    var closestPoint = this.level.closestPoint(this.pos, this.size * 2);
    if(closestPoint[0] < this.size) {
	if(closestPoint[2]["onTouch"]) {
	    closestPoint[2]["onTouch"]();
	}
        var push = closestPoint[1].get();
        push.sub(this.pos);
        push.normalize();
        var normal = push.get();
        push.mult(this.size - closestPoint[0]);
        this.pos.sub(push);
        var accel = normal.get();
        accel.mult(this.vel.dot(normal));
        if(this.vel.dot(normal) > 7) {
            accel.mult(1.5);
        }
        this.vel.sub(accel);

        this.gravity = normal.heading() - Math.PI * 0.5;
        
        if(keys[38]) {
            var force = gravity.get();
            force.mult(-30);
            this.vel.add(force);
        }
    }
    var accel = side.get();
    accel.mult(this.vel.dot(side) * 0.5);
    this.vel.sub(accel);

    if(keys[37]) {
        this.vel.add(side);
    }
    if(keys[39]) {
        this.vel.sub(side);
    }
};

@@ -1236,17 +1236,17 @@
 .size * 
-2
+6
 );%0A    i
@@ -1741,66 +1741,8 @@
 el);
-%0A%0A        this.gravity = normal.heading() - Math.PI * 0.5;
 %0A   
@@ -1867,24 +1867,24 @@
 add(force);%0A
-
         %7D%0A  
@@ -1876,24 +1876,641 @@
 );%0A        %7D
+%0A%0A        this.gravity = normal.heading() - Math.PI * 0.5;%0A    %7D else %7B%0A%09if(closestPoint%5B0%5D %3C this.size * 4) %7B%0A            var normal = closestPoint%5B1%5D.get();%0A            normal.sub(this.pos);%0A            normal.normalize();%0A            var newGravity = normal.heading() - Math.PI * 0.5;%0A%09    var angleDiff = (newGravity - this.gravity);%0A%09    while(angleDiff %3C -Math.PI) %7B%0A%09%09angleDiff += Math.PI * 2;%0A%09%09this.gravity -= Math.PI * 2;%0A%09    %7D%0A%09    while(angleDiff %3E Math.PI) %7B%0A%09%09angleDiff -= Math.PI * 2;%0A%09%09this.gravity += Math.PI * 2;%0A%09    %7D%0A%09    this.gravity += angleDiff * (1 - (closestPoint%5B0%5D / (this.size * 4)));%0A%09%7D
 %0A    %7D%0A    v

Add gravitational safety net