Skip to content

Commit

Permalink
Josh comments
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielBelmes committed Nov 21, 2023
1 parent 23c0636 commit 0ffa7c8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/components/BubbleEmitterComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export const BubbleEmitterComponent = defineComponent({
* Remove bubble entity from emitter
*/
export function removeBubble(emitterEntity: Entity, bubbleEntity: Entity): void {
const emitter = getMutableComponent(emitterEntity, BubbleEmitterComponent)
const emitter = getMutableComponent(emitterEntity, BubbleEmitterComponent) // Reactive incase someone wants to use it reactively
const currEntities = emitter.bubbleEntities.get(NO_PROXY)!
const index = currEntities.indexOf(bubbleEntity);
if (index > -1) { // only splice array when item is found
Expand All @@ -136,7 +136,7 @@ export function removeBubble(emitterEntity: Entity, bubbleEntity: Entity): void
export function ageEmitterBubbles(emitterEntity: Entity, deltaSeconds: number): void {
const emitter = getComponent(emitterEntity, BubbleEmitterComponent)
for(const bubbleEntity of emitter.bubbleEntities!) {
const bubble = getMutableComponent(bubbleEntity, BubbleComponent) // getMutable gets the reactified version of the component that will respond to effects
const bubble = getMutableComponent(bubbleEntity, BubbleComponent) // getMutable gets the reactified version of the component that will respond to effects(if you want to try checking age reactively)
const currAge = bubble.age.get(NO_PROXY)
bubble.age.set(currAge+deltaSeconds) // increment individual bubble age.
}
Expand Down
8 changes: 5 additions & 3 deletions src/systems/BubbleSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Vector3 } from "three";
import { SimulationSystemGroup } from "@etherealengine/engine/src/ecs/functions/EngineFunctions";

const bubbleEmitterQuery = defineQuery([BubbleEmitterComponent])
const velocity = new Vector3(0,0,0)

export const BubbleSystem = defineSystem({
uuid: "BubbleSystem",
Expand All @@ -17,10 +18,11 @@ export const BubbleSystem = defineSystem({
// [Exercise 2]: Using the below basic setup. Move every bubble not just the first one
const tempvector = new Vector3(0,0,0)
const emitterComponent = getComponent(entity, BubbleEmitterComponent)
const localTransform = getMutableComponent(emitterComponent.bubbleEntities![0], LocalTransformComponent)
const localTransform = getComponent(emitterComponent.bubbleEntities![0], LocalTransformComponent)
if(!localTransform) continue;
tempvector.addVectors(localTransform.position.value, emitterComponent.direction.clone().multiplyScalar(emitterComponent.speed))
localTransform.position.get(NO_PROXY).copy(tempvector)
velocity.copy(emitterComponent.direction).multiplyScalar(emitterComponent.speed)
tempvector.addVectors(localTransform.position, velocity)
localTransform.position.copy(tempvector)

// [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
Expand Down

0 comments on commit 0ffa7c8

Please sign in to comment.