Add ship movement
This commit is contained in:
parent
09b3df649c
commit
4959519f39
15 changed files with 278 additions and 77 deletions
|
@ -8,12 +8,15 @@ export default class Body {
|
|||
this.xvel = 0;
|
||||
this.yvel = 0;
|
||||
this.rvel = 0;
|
||||
this.rfriction = 0.9;
|
||||
this.mass = mass;
|
||||
}
|
||||
|
||||
tickMotion() {
|
||||
this.x += this.xvel;
|
||||
this.y += this.yvel;
|
||||
this.r += this.rvel;
|
||||
this.rvel *= this.rfriction;
|
||||
}
|
||||
|
||||
tickGravity(bodies) {
|
||||
|
@ -40,4 +43,10 @@ export default class Body {
|
|||
this.xvel = 0;
|
||||
this.yvel = 0;
|
||||
}
|
||||
|
||||
applyDirectionalForce(x, y, r) {
|
||||
this.xvel += (x * Math.cos(this.r) - y * Math.sin(this.r)) / this.mass;
|
||||
this.yvel += (y * Math.cos(this.r) - x * Math.sin(this.r)) / this.mass;
|
||||
this.rvel += r / this.mass;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue