Projectile Launch is a type of query that will query objects as a projectile hits them. Because of this, each query will only return 1 object, but each projectile will trigger multiple queries. Since this is a query, it doesn’t do anything to the items it gets, see the non-query topdown mechanics for examples of using a query!
Example Usage
No scene solely used for the Projectile Launch exists, but you can see it in action in the Do Damage Whitebox
Setup
Download all the mechanics on the Getting Started page
- Drag the script ProjectileLaunch.cs (located in Scripts/CharacterMechanics/TopDownMechanics/Queries) onto an empty child of your character, like in the image below:
- Add the camera your player is viewing from in the “Viewport” property
- Add the prefab for your projectile. This projectile needs to have a Rigidbody and must have QueryingProjectile.cs (located in Scripts/EnvironmentalMechanics) attached so that the projectile can pass the objects it hits to the ProjectileLaunch query.

- If you’d like to change how your projectile moves about the world, tweak the Rigidbody to your liking. In the Damage Whitebox, the projectile has its rotation frozen, along with its position on the y axis.
- If you don’t want your projectile to collide with certain objects (whether that be things like the player, a certain group of walls, or other projectiles), you can have it be on a custom layer and edit the collision group interactions by going to Edit > Project Settings > Physics > Layer Collision Matrix
- Add a keybind to launch your projectile, like below:
- Add a keybind to aim your projectile, like below. Also click the gear and set the ActionType to PassThrough and the ControlType to Vector2. Here, the right stick is set on each axis individually to limit it to shooting in the 4 Cardinal Directions + the 4 Diagonals (through combinations of the cardinals)
- Set other properties as you need to to query the exact game objects you need for your mechanic, you can see more information below!
Customization
Properties
-
- Viewport – The camera the player is viewing from
- Projectile Prefab – This projectile will be launched. Object must have a rigidbody attached.
- Launch Speed – The speed of this projectile when it’s launched.
- Speed Loss On Collision – Additional velocity loss when the projectile collides with something. The engine may already reduce velocity based on elasticity and friction values. To more finely control this, use a physics material on your projectile prefab.
- Maximum Distance – The maximum distance the projectile can travel before being destroyed.
- Maximum Time Active – The maximum time the projectile has before being destroyed.
- Maximum Objects To Hit – How many objects the projectile can hit. On the final object, the projectile will disappear.
- Allowed Layers – Only objects on these layers will be queried when hit. Other objects will still have collisions.
- Query Collisions With Disallowed Layers – If true, collisions with disallowed layers will be queried, but not count towards the MaximumObjects count.
- Cooldown – The time to wait between launches.
- Launch – The input to launch the projectile with.
- Target – The input to target the direction the projectile is launched in. If mouse position is used, the target will be where the mouse clicks. If Up/Down/Left/Right composite is used, the target will be positioned relative to the origin in that direction from the camera. Otherwise, the projectile will fire in the direction the character is looking.
- Snap Target To Y Plane – If true, or if the target is a 2d vector, the targeted point will always be on the same lateral plane as this transform, if false and the player is targeting with a mouse, the target will be where a ray from the camera at the mouse point intersects an object in the world.
Events
-
- OnHit<List<(Collider, Vector)>>
- Fires when the query happens, provides a list of tuples of the collider hit and where the collider was hit as a point in world space
- ProjectileLaunched<QueryingProjectile>
- Fires after the projectile is first created and launched from the character, passes the projectile created
- ProjectileCollided<QueryingProjectile, Collision>
- Fires when OnHit fires, but passes the projectile, along with all information about the collision instead of just the collider and point hit
- ProjectileDestroying<QueryingProjectile>
- Fires right before the projectile is destroyed, for any last minute changes
- OnHit<List<(Collider, Vector)>>
Caveats/Bugs
- None known at this time





