Skip to content

Commit

Permalink
fix: optimize 2d colliders and rigidbodies
Browse files Browse the repository at this point in the history
  • Loading branch information
Gugustinette committed Oct 23, 2024
1 parent 5b02f2e commit 861aec7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
13 changes: 11 additions & 2 deletions packages/2d/src/core/FCollider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,17 @@ export class FCollider {

frame(_delta: number): void {
// As the collider should have moved, update the transform to sync with the collider
this.transform.position = this.__COLLIDER__.translation()
this.transform.rotation = this.__COLLIDER__.rotation()
this.transform.__POSITION__ = this.__COLLIDER__.translation()
this.transform.__ROTATION__ = this.__COLLIDER__.rotation()
// Propagate the position and rotation update if the collider is attached to a component
if (this.component) {
// Propagate the position update
this.component.__UPDATE_POSITION__()
this.component.sensor?.__UPDATE_POSITION__()
// Propagate the rotation update
this.component.__UPDATE_ROTATION__()
this.component.sensor?.__UPDATE_ROTATION__()
}
}

/**
Expand Down
13 changes: 11 additions & 2 deletions packages/2d/src/core/FRigidBody.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,17 @@ export class FRigidBody {

frame(_delta: number): void {
// As the rigidBody should have moved, update the transform to sync with the rigidBody
this.transform.position = { x: this.__RIGIDBODY__.translation().x, y: this.__RIGIDBODY__.translation().y }
this.transform.rotation = this.__RIGIDBODY__.rotation()
this.transform.__POSITION__ = this.__RIGIDBODY__.translation()
this.transform.__ROTATION__ = this.__RIGIDBODY__.rotation()
// Propagate the position and rotation update if the rigidBody is attached to a component
if (this.component) {
// Propagate the position update
this.component.__UPDATE_POSITION__()
this.component.sensor?.__UPDATE_POSITION__()
// Propagate the rotation update
this.component.__UPDATE_ROTATION__()
this.component.sensor?.__UPDATE_ROTATION__()
}
}

/**
Expand Down

0 comments on commit 861aec7

Please sign in to comment.