Skip to content

Commit 9e29823

Browse files
For performance reasons, don't sync static objects to physics every frame
1 parent 2c769b4 commit 9e29823

File tree

4 files changed

+15
-3
lines changed

4 files changed

+15
-3
lines changed

AmmoDriver.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,15 @@ An `ammo-body` component may be added to any entity in a scene. While having onl
134134
The `type` of an ammo body can be one of the following:
135135

136136
- `dynamic`: A freely-moving object. Dynamic bodies have mass, collide with other bodies, bounce or slow during collisions, and fall if gravity is enabled.
137+
137138
- `static`: A fixed-position object. Other bodies may collide with static bodies, but static bodies themselves are unaffected by gravity and collisions. These bodies should typically not be moved after initialization as they cannot impart forces on `dynamic` bodies.
139+
140+
- If you do re-position a static object after initialization, you'll need to explicitly update the physics system with the new position. You can do that like this:
141+
142+
```
143+
this.el.components['ammo-body'].syncToPhysics();
144+
```
145+
138146
- `kinematic`: Like a `static` body, except that they can be moved via updating the position of the entity. Unlike a `static` body, they impart forces on `dynamic` bodies when moved. Useful for animated or remote (networked) objects.
139147
140148
#### Activation States

dist/aframe-physics-system.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16566,7 +16566,9 @@ let AmmoBody = {
1656616566

1656716567
beforeStep: function() {
1656816568
this._updateShapes();
16569-
if (this.data.type !== TYPE.DYNAMIC) {
16569+
// Note that since static objects don't move,
16570+
// we don't sync them to physics on a routine basis.
16571+
if (this.data.type === TYPE.KINEMATIC) {
1657016572
this.syncToPhysics();
1657116573
}
1657216574
},

dist/aframe-physics-system.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/body/ammo-body.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,9 @@ let AmmoBody = {
356356

357357
beforeStep: function() {
358358
this._updateShapes();
359-
if (this.data.type !== TYPE.DYNAMIC) {
359+
// Note that since static objects don't move,
360+
// we don't sync them to physics on a routine basis.
361+
if (this.data.type === TYPE.KINEMATIC) {
360362
this.syncToPhysics();
361363
}
362364
},

0 commit comments

Comments
 (0)