Skip to main content

Projectile

This section shows how to apply your Damage GraphObject to a projectile using CombatDamage and physics detection.

Prerequisites

Before starting, make sure:

  • You already have a player character and a enemy character, a controller script, and an attack animation
  • You have created a Damage Graph GraphObject (from the previous guide)
  • An EntityComponent has been added to the player prefab and enemy prefab (from the previous guide)

Step-by-Step Setup

  1. Drag out your projectile model prefab or simply create a cube and scale it to a proper size, and put it under the Player prefab.
  2. Add a CombatDamage component to it.
  3. Drag the GraphObject you created into the Graph field of the CombatDamage component.
  4. Drag the player’s EntityComponent into the Dealer Entity slot under Optional References section.
  5. Enable Enable Physics Detection under the Physics Detection section.
  6. Set Detection Mode to Rigidbody Collider.
    • Click all red Auto Fix buttons if any are shown.
  7. In the LayerMask field, select the layer used by your enemy prefab.
  8. In the Tag Filter section, add a new tag:
    • hostile
  9. Set Projectile Mode to Physics Drive under Projectile section.
    • Click all red Auto Fix buttons if any are shown.
  10. Enable Auto-seeking Targets.
  11. Now the projectile is ready to use, Deactivate it so it does not fire in the begining.
  12. To test it, you could set a keycode in your code to instantiate and activate it.
public GameObject myProjectile;

public void Fire(){
GameObject _newProjectile = Instantiate(myProjectile);
_newProjectile.SetActive(true);
}

void Update(){
if (Input.GetKeyDown(KeyCode.Space))Fire();
}