Skip to content

Projectile Entities

kk4w4i edited this page Aug 31, 2023 · 3 revisions

Overview

Projectiles allow entities to do damage from range. This range is determined by its target location.

Implementation

Projectiles are created utilizing the ProjectileFactory which Creates a projectile entity using a target vector and shooter entity. The target vector is the location where the bullet will be fired to, despawning upon arrival. This is done utilizing a movement task where the destination is set using the target vector. The stats for the bullet are pulled from the shooter entities config so the damage scales with the shooter's damage. The projectile entity is created and has a physicsComponent, PhysicsMovementComponent, HitboxComponent, ProjectileAttackComponent, combatStatsComponent, AiComponent and EnemyAnimationComponent . The projectile attack component is created so the projectile will explode on contact with players, walls, structures and non ranged enemies.

After creation, the projectile can be spawned using the entity placement service.

Example code of creating bullet and spawning in at a certain location:

Task

ProjectileMovementTask

This tasks assigns the projectile entity to move in a straight line, it updates movement similar to the chase task without the retargeting.
If the projectile misses the target it will eventually dispose itself when it reaches the initial destination.

Components

ProjectileAttackComponent

This component acts similar to the TouchAttackComponent except projectile behaviour is added. The differeince in behaviour is a simple dispose() added to after the entity touches the target -> Hits the target (deals damage) -> Disposes(with animation triggers)

Future Implementation

  • lower the redundancy of the Code, since the TouchAttack and ProjectileAttack is very similar, possibly merging the code and adding conditional logic to determine if it's a bullet or not may be required.
  • Sprint 1 only had enemies shooting projectiles which meant task setups to shoot the projectile were coded just for enemies (Check enemies feature tasks), for other entities like turrets and guns(Player weapons) new tasks may be required to shoot depending on the method of triggering the projectile.
Clone this wiki locally