# Source URL: https://dev.epicgames.com/community/snippets/BdoW/fortnite-spongebob-roguelike-snippets
# Local doc: epic-docs/community/snippets/BdoW/fortnite-spongebob-roguelike-snippets.md
using { /Verse.org/Simulation }
using { /Verse.org/SceneGraph }
using { /Fortnite.com/Characters }
using { /UnrealEngine.com/Temporary/SpatialMath }
# This container component allows us to spawn a"container" entity wherever we want, in this case the players location. Once spawned
# it checks for children entities with the "projectile_component", which then handles the projectile logic on their own.
# This allows for rapid creation and iteration of projectiles, because you can simply place as many child entities within the container entity
# as you want, and as long as the container has the "projectile_container_component" and the children have the
# "projectile_component" added, they will handle all gameplay logic
projectile_container_component := class<final_super>(component):
# Spawned in entities default to the origin of the simulation, this function sets the global transform of the container entity to that of
# the players current location.
SetProjectileGlobalTransform(PlayerAgent:agent): void =
if(SpawningFortChar:= PlayerAgent.GetFortCharacter[]):
PlayerTransform := SpawningFortChar.GetTransform()
PlayerTranslation := PlayerTransform.Translation
Entity.SetGlobalTransform(FromTransform(PlayerTransform))
InitChildrenEntities(PlayerAgent)
# Checks if any of the children entities attatched to this entity have the "projectile_component" component, and if so
# runs the "InitProjectile" function.
InitChildrenEntities(PlayerAgent:agent): void =
ChildEntities := Entity.GetEntities()
for(ChildEntity:ChildEntities):
if(Component := ChildEntity.GetComponent[projectile_component]):
Component.InitProjectile(PlayerAgent)
Expand code Copy full snippet(31 lines long)
* ```
Verse Library
verse
03 Snippet
Manages and spawns projectile child entities at the player position using the Verse Scene Graph for rapid iteration.
extracted-snippets/community/snippets/BdoW/fortnite-spongebob-roguelike-snippets/03-snippet.verse
Sign in free to read the full source 🌴
This Verse Library file is members-only. Create a free account to view the complete source and download the .verse file.