- Home /
Instantiating blood on walls using gameobject
Currently I use a system like this for bullet holes
if (hit.collider.tag == "Terrain")
{
Debug.Log("We hit terrain");
if (myCurrentWeapon == 1 && shotgunAmmo >= 0)
{
Instantiate(bulletHoleEffect, hit.point + (hit.normal * floatInFrontOfWall), Quaternion.LookRotation(hit.normal));
}
I'd like to use something like that for my blood effects too.
Currently when an enemy gets shot a "Blood" Gameobject shoots out in a random direction, when that object hits an object tagged "Terrain" I'd like it to instantiate blood on the terrain facing the same direction as the terrain, currently this is what I'm trying.
void OnCollisionEnter(Collision other)
{
if (other.gameObject.tag == "Terrain")
{
Debug.Log("We Collided With Something");
Instantiate(bloodEffect, other.contacts[0].point + (other.contacts[0].point * floatInFrontOfWall), Quaternion.LookRotation(other.contacts[0].point));
}
}
Doesn't seem to work though. Probably either because I'm using contact wrong or because you can't do contacts.point.normal
Currently it instantiates at the correct point, but it does not face the correct direction.
Answer by Cherno · May 01, 2016 at 11:31 PM
Instantiate(bloodEffect, other.contacts[0].point + (other.contacts[0].point * floatInFrontOfWall), Quaternion.LookRotation(other.contacts[0].point));
But, you are not even accessing ContactPoint.normal?!?
Edit:
It should be something like
Instantiate(bloodEffect, other.contacts[0].point + (other.contacts[0].point * floatInFrontOfWall), Quaternion.LookRotation(other.contacts[0].normal));
I don't know how to use contact, what am I doing wrong? How is is supposed to be done?
I linked to the variable you need, so I'm not sure where your problem is.
It should be something like
Instantiate(bloodEffect, other.contacts[0].point + (other.contacts[0].point * floatInFrontOfWall), Quaternion.LookRotation(other.contacts[0].normal));
I thought I had to call point.normal which wasn't possible. Just .normal works though, make an an answer so I can accept.