Hey guys!
I’m trying to make the blood splatter in the direction that the player attacks, like in the below picture:
I’ve managed to get a solution but wanted to ask if it’s the right way to go about it! I feel like I’m on the right lines but not sure if I’m calculating the angle in the right wat. Here’s what I’ve done:
- Changed the shape of the particle system to a cone
- Updated the rotation of the particle system to x: -90 (so the cone faces in the 2D space, rather than facing the camera)
- When the particle system is created, get the angle between the player and enemy then rotate the Y axis of the particle system shape property
Here’s the code that is part of the EnemyHealth class.
private void DetectDeath()
{
if(currentHealth <= 0)
{
// create the particle effect prefab and get the ParticleSystem
ParticleSystem obj = Instantiate(deathVFXPrefab,
transform.position, Quaternion.Euler(new Vector3(-90,0,0))
).GetComponent<ParticleSystem>();
// Get the shape property of the particle system
var shape = obj.shape;
// Calculate the rotation between where the player is and where the enemy is
var angleY = Vector3.Angle(PlayerController.Instance.transform.position, this.transform.position);
// Apply the angle on the Y axis to the shape
shape.rotation = new Vector3(0, angleY, 0);
Destroy(gameObject);
}
}