Skip to content

Commit

Permalink
fix: add return if static to physics apply force functions (#443)
Browse files Browse the repository at this point in the history
  • Loading branch information
dragoncoder047 authored Nov 29, 2024
1 parent b91b393 commit ac2d90f
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/components/physics/body.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ export interface BodyComp extends Comp {
*/
damping: number;
/**
* If object is static, won't move, and all non static objects won't move past it.
* If object is static, it won't move, all non static objects won't move past it, and all
* calls to addForce(), applyImpulse(), or jump() on this body will do absolutely nothing.
*/
isStatic: boolean;
/**
Expand Down Expand Up @@ -160,7 +161,8 @@ export interface BodyCompOpt {
*/
gravityScale?: number;
/**
* If object is static, won't move, and all non static objects won't move past it.
* If object is static, it won't move, all non static objects won't move past it, and all
* calls to addForce(), applyImpulse(), or jump() on this body will do absolutely nothing.
*
* @since v3000.0
*/
Expand Down Expand Up @@ -472,15 +474,18 @@ export function body(opt: BodyCompOpt = {}): BodyComp {
},

applyImpulse(impulse: Vec2) {
if (this.isStatic) return;
this.vel = this.vel.add(impulse);
},

addForce(force: Vec2) {
if (this.isStatic) return;
acc.x += force.x / this.mass;
acc.y += force.y / this.mass;
},

jump(force: number) {
if (this.isStatic) return;
curPlatform = null;
lastPlatformPos = null;
this.vel = getGravityDirection().scale(
Expand Down

0 comments on commit ac2d90f

Please sign in to comment.