add ship rendering and damping
This commit is contained in:
parent
05ad81ed8d
commit
80bd84230d
22 changed files with 66 additions and 6 deletions
|
@ -25,6 +25,8 @@ class Physics {
|
|||
bodyDef.active = true;
|
||||
bodyDef.linearVelocity = new b2Vec2(body.xvel / s || 0, body.yvel / s || 0);
|
||||
bodyDef.angularVelocity = body.rvel || 0;
|
||||
bodyDef.linearDamping = 0.001;
|
||||
bodyDef.angularDamping = 0.001;
|
||||
bodyDef.type = body.type == 'static' ?
|
||||
Box2D.b2BodyType.b2_staticBody : Box2D.b2BodyType.b2_dynamicBody;
|
||||
if (body.player) bodyDef.allowSleep = false;
|
||||
|
|
|
@ -22,18 +22,18 @@ class Ship extends Body {
|
|||
}
|
||||
|
||||
if (data.forward) {
|
||||
let power = 0.02;
|
||||
let power = 0.05;
|
||||
let x = Math.cos(this.b2body.GetAngleRadians()) * power;
|
||||
let y = Math.sin(this.b2body.GetAngleRadians()) * power;
|
||||
this.applyForce(x, y);
|
||||
}
|
||||
|
||||
if (data.left) {
|
||||
this.applyTorque(-0.02);
|
||||
this.applyTorque(-0.0001);
|
||||
}
|
||||
|
||||
if (data.right) {
|
||||
this.applyTorque(0.02);
|
||||
this.applyTorque(0.0001);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue