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
- 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.
- Add a CombatDamage component to it.
- Drag the GraphObject you created into the
Graphfield of the CombatDamage component. - Drag the player’s EntityComponent into the
Dealer Entityslot underOptional Referencessection. - Enable
Enable Physics Detectionunder thePhysics Detectionsection. - Set
Detection ModetoRigidbody Collider.- Click all red
Auto Fixbuttons if any are shown.
- Click all red
- In the
LayerMaskfield, select the layer used by your enemy prefab. - In the
Tag Filtersection, add a new tag:hostile
- Set
Projectile ModetoPhysics DriveunderProjectilesection.- Click all red
Auto Fixbuttons if any are shown.
- Click all red
- Enable
Auto-seeking Targets. - Now the projectile is ready to use, Deactivate it so it does not fire in the begining.
- 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();
}