-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(REVIEW ONLY) Jeremy bubble exercises #1
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
45437a1
Exercise 1: spawn multiple bubbles
Rezmason a219809
Exercise 2: move every bubble, not just the first one.
Rezmason 36be1d0
Exercise 3: remove bubbles if they reach the age threshold
Rezmason 51ce7f7
Exercise 4: detect if the player is near a bubble and remove it
Rezmason File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ import { NO_PROXY, getState } from "@etherealengine/hyperflux" | |
import { useExecute } from "@etherealengine/engine/src/ecs/functions/SystemFunctions" | ||
import { SimulationSystemGroup } from "@etherealengine/engine/src/ecs/functions/EngineFunctions" | ||
import { EngineState } from "@etherealengine/engine/src/ecs/classes/EngineState" | ||
import { LocalTransformComponent } from "@etherealengine/engine/src/transform/components/TransformComponent" | ||
|
||
export const BubbleEmitterComponent = defineComponent({ | ||
//name: The human-readable label for the component. This will be displayed in the editor and debugging tools. | ||
|
@@ -92,21 +93,31 @@ export const BubbleEmitterComponent = defineComponent({ | |
// Spawning a single bubble as an example | ||
// [Exercise 1]: Using this system. Spawn multiple bubbles with varying x,z Localtransform positons | ||
// [Exercise 3]: Remove them if they are too old(bubble.age > N seconds)[This can be done in a couple ways(reactively and within this sytem synchronosly)] | ||
if(emitterComponent.bubbleEntities.value!.length < 1) { //For example ensuring there is only one bubble being added | ||
const bubbles: Array<Entity> = [] | ||
const numExistingBubbles = emitterComponent.bubbleEntities.value!.length | ||
const numBubbles = 10 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd prefer this constant to actually be at the top of the file or configured withing the emitter component |
||
for (let i = numExistingBubbles; i < numBubbles; i++) { | ||
const bubbleEntity = createEntity() | ||
setComponent(bubbleEntity, BubbleComponent) | ||
setComponent(bubbleEntity, LocalTransformComponent, { | ||
position: new Vector3((Math.random() - 0.5) * 100, 0, (Math.random() - 0.5) * 100) | ||
}) | ||
setComponent(bubbleEntity, EntityTreeComponent, { | ||
parentEntity: entity, | ||
uuid: MathUtils.generateUUID() as EntityUUID | ||
}) | ||
emitterComponent.bubbleEntities.merge([bubbleEntity]) | ||
bubbles.push(bubbleEntity) | ||
} | ||
emitterComponent.bubbleEntities.merge(bubbles) | ||
|
||
const bubble = getComponent(emitterComponent.bubbleEntities.value![0], BubbleComponent) | ||
|
||
if(bubble.age >= 5) { // Delete one bubble after its age is greater than 5 seconds | ||
removeBubble(entity,emitterComponent.bubbleEntities.value![0]) | ||
const bubbleEntities = emitterComponent.bubbleEntities.value!.slice() | ||
for (const bubbleEntity of bubbleEntities) { | ||
const bubble = getComponent(bubbleEntity, BubbleComponent) | ||
if (bubble.age >= 5) { | ||
removeBubble(entity, bubbleEntity) | ||
} | ||
} | ||
|
||
}, { after: SimulationSystemGroup }) | ||
|
||
return null | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
using emitterComponent.bubbleEntities was enough to track the bubbles.