2.0 Help

Projectile Component

The projectile component makes an object move along a straight line (with optional gravity), checks for collisions and triggers surface interactions. It also applies damage and a physical impulse when it hits something.

There are many ways projectiles may work in different games. The projectile component only implements the most commonly needed functionality. For some games this may already be sufficient. For more creative games you most certainly need to implement your own component. The built-in projectile component is mostly meant as a showcase and demonstration, how you can generally implement such functionality, especially how to interact with surfaces.

Component Properties

  • Speed: The speed (m/sec) at which the projectile will fly along the +X axis. For dramatic effect it is often more interesting for bullets to fly much slower than is realistic, so that one can see them.

  • GravityMultiplier: How strong gravity should affect the bullet. If set to 0, the projectile will fly straight ahead. With values > 0, it will fall downwards.

  • MaxLifetime: If the projectile lives longer than this, it will destroy itself.

  • SpawnPrefabOnStatic: If enabled, the OnDeathPrefab will be spawned when the projectile lost so much speed that it is nearly static (not moving anymore). Only useful in combination with the bounce behavior.

  • OnDeathPrefab: If the projectile destroys itself because it didn't hit anything before MaxLifetime ended or it slowed to a halt and SpawnPrefabOnStatic is enabled, it will spawn this prefab. Can be used to let rockets 'explode' after a while.

  • CollisionLayer: The physics collision layer to use for raycasting whether the projectile hit something.

  • ShapeTypesToHit: Specifies what types of physics geometry to hit, at all.

  • FallbackSurface: If the projectile hits something that has no surface assigned, it will assume that this type of surface was hit. This just guarantees that you always get any kind of hit response, even when the hit geometry is just dummy or placeholder geometry.

  • Interactions: This array allows you to specify exactly what the projectile will do, when it hits different types of surfaces. Each entry is used to configure the action of the projectile if a certain type of surface is hit. Note that surfaces and surface interactions already work hierarchically. That means for most types of projectiles this array only needs to contain a single entry, with a base surface, and all it needs to specify is what 'interaction' to trigger. The exact type of surface that is hit, will then decide what prefabs to spawn for that kind of interaction.

Interaction Properties

  • Surface: The (base) type of surface for which this array element applies.

  • Reaction: How the projectile itself should react. Absorb means it will stop there, Reflect means the bullet will bounce off without speed loss, Bounce means it will bounce off with a loss in speed depending on the restitutation of the hit surface, Attach means the bullet will stop but attach itself to the target object and Pass Through means it will continue on its path.

  • Interaction: The surface interaction to trigger when the projectile hits this type of surface.

  • Impulse: The amount of physical impulse to exert on the hit object.

  • Damage: The amount of damage to apply to the hit object.

See Also

Last modified: 16 August 2024