Skip to content

Commit 517c066

Browse files
committed
Physics API Abstraction
1 parent 7ef290d commit 517c066

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/BasicSystem.tsx

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
import React, { useEffect } from 'react'
22

3-
import { Engine, EntityUUID } from '@etherealengine/ecs'
43
import { isClient } from '@etherealengine/common/src/utils/getEnvironment'
5-
import { SimulationSystemGroup, defineSystem, getComponent, setComponent } from '@etherealengine/ecs'
4+
import {
5+
Engine,
6+
EntityUUID,
7+
SimulationSystemGroup,
8+
UUIDComponent,
9+
defineSystem,
10+
getComponent,
11+
setComponent
12+
} from '@etherealengine/ecs'
613
import { ECSState } from '@etherealengine/ecs/src/ECSState'
714
import { PrimitiveGeometryComponent } from '@etherealengine/engine/src/scene/components/PrimitiveGeometryComponent'
815
import { GeometryTypeEnum } from '@etherealengine/engine/src/scene/constants/GeometryTypeEnum'
@@ -17,7 +24,7 @@ import {
1724
} from '@etherealengine/hyperflux'
1825
import { NetworkState, NetworkTopics, WorldNetworkAction } from '@etherealengine/network'
1926
import { NameComponent } from '@etherealengine/spatial/src/common/NameComponent'
20-
import { UUIDComponent } from '@etherealengine/ecs'
27+
import { Physics } from '@etherealengine/spatial/src/physics/classes/Physics'
2128
import { ColliderComponent } from '@etherealengine/spatial/src/physics/components/ColliderComponent'
2229
import { RigidBodyComponent } from '@etherealengine/spatial/src/physics/components/RigidBodyComponent'
2330
import { VisibleComponent } from '@etherealengine/spatial/src/renderer/components/VisibleComponent'
@@ -98,7 +105,7 @@ const BasicObject = ({ entityUUID }: { entityUUID: EntityUUID }) => {
98105
const angle = Math.random() * Math.PI * 2
99106
const direction = new Vector3(Math.sin(angle), 0, Math.cos(angle))
100107
const velocity = 0.025 + Math.random() * 0.01
101-
getComponent(entity, RigidBodyComponent).body.applyImpulse(direction.multiplyScalar(velocity), true)
108+
Physics.applyImpulse(entity, direction.multiplyScalar(velocity))
102109
}, [entity])
103110

104111
return null
@@ -123,7 +130,7 @@ const execute = () => {
123130
counter = 0
124131

125132
const entityUUID = `basic-${elapsedSeconds}` as EntityUUID
126-
const action = BasicActions.spawnAction({
133+
const action = BasicActions.spawnAction({
127134
parentUUID: getComponent(Engine.instance.originEntity, UUIDComponent),
128135
entityUUID,
129136
position: new Vector3(Math.random(), 1, Math.random())

0 commit comments

Comments
 (0)