Hello,
I’m having an issue rotating instantiated blood based on the raycasthit.point and raycasthit.normal values. Essentially the blood should spurt where the raycast was shot from. I’m not sure if I should be using the raycast origin or direction for this instead of the hit and normal values. I have a script on my weapon that looks like the following:
if (hitSomething)
{
EnemyHitbox enemyHitbox = hit.collider.GetComponent<EnemyHitbox>();
if (bulletDecalPrefab != null)
{
//Draw decal on surface hit
GameObject decal = (GameObject)Instantiate(bulletDecalPrefab, Vector3.zero, Quaternion.identity);
Vector3 oldScale = decal.transform.localScale;
decal.transform.parent = hit.transform;
decal.transform.position = hit.point+(hit.normal*0.005f);
decal.transform.LookAt(hit.point-hit.normal);
if (hit.transform.lossyScale != Vector3.one)
{
decal.transform.parent = null;
decal.transform.localScale = oldScale;
decal.transform.parent = hit.transform;
}
}
if (enemyHitbox != null)
{
enemyHitbox.TakeDamage(damage, hit.point, hit.normal);
}
Then my enemies hitbox script has the following in it to detect the hit and instantiate the blood on the hit location:
public void TakeDamage(int amount, Vector3 hitPoint, Vector3 hitNormal)
{
if (enemyHealth.isDead)
return;
Instantiate(Blood, hitPoint, Quaternion.LookRotation(hitNormal));
enemyHealth.currentHealth -= amount*damageMultiplier;
// Blood.transform.LookAt(-rayDirection);
if (enemyHealth.currentHealth <= 0)
{
enemyHealth.Death();
}
}
I’ve been scratching my head for a few hours on this one. Any help would be greatly appreciated.