Skip to content

Commit

Permalink
Exercise 4: detect if the player is near a bubble and remove it
Browse files Browse the repository at this point in the history
  • Loading branch information
Rezmason committed Dec 8, 2023
1 parent 36be1d0 commit 51ce7f7
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/systems/BubbleSystem.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import { defineQuery, getComponent, getMutableComponent } from "@etherealengine/engine/src/ecs/functions/ComponentFunctions";
import { defineSystem } from "@etherealengine/engine/src/ecs/functions/SystemFunctions";
import { BubbleEmitterComponent, removeBubble } from "../components/BubbleEmitterComponent";
import { LocalTransformComponent } from "@etherealengine/engine/src/transform/components/TransformComponent";
import { BubbleComponent } from "../components/BubbleComponent";
import { LocalTransformComponent, TransformComponent } from "@etherealengine/engine/src/transform/components/TransformComponent";
import { NO_PROXY, getState } from "@etherealengine/hyperflux";
import { EngineState } from "@etherealengine/engine/src/ecs/classes/EngineState";
import { Vector3 } from "three";
import { SimulationSystemGroup } from "@etherealengine/engine/src/ecs/functions/EngineFunctions";
import { AvatarComponent } from "@etherealengine/engine/src/avatar/components/AvatarComponent";
import { EntityTreeComponent } from "@etherealengine/engine/src/ecs/functions/EntityTree";

const bubbleEmitterQuery = defineQuery([BubbleEmitterComponent])
const bubbleQuery = defineQuery([BubbleComponent])
const avatarQuery = defineQuery([AvatarComponent, TransformComponent])
const velocity = new Vector3(0,0,0)

export const BubbleSystem = defineSystem({
Expand All @@ -28,5 +33,16 @@ export const BubbleSystem = defineSystem({
// [Exercise 4]: Utilizing an AvatarComponent Query, TransformComponent positions of bubble entities, and Vector3.distanceTo
// Detect if the player is near a bubble and remove it
}

for (const bubbleEntity of bubbleQuery()) {
const bubbleWorldPosition = getComponent(bubbleEntity, TransformComponent).position
for (const avatarEntity of avatarQuery()) {
if (getComponent(avatarEntity, TransformComponent).position.distanceTo(bubbleWorldPosition) < 1) {
const emitter = getComponent(bubbleEntity, EntityTreeComponent).parentEntity!
removeBubble(emitter, bubbleEntity)
break
}
}
}
}
})

0 comments on commit 51ce7f7

Please sign in to comment.