I am trying to make a blood splatter in unity but am not having much luck. I want to make it so that when you shoot someone, the splatter is created and than it checks where the ground is beneath it, positioning itself on top of the ground (+0.01 or something so it doesn’t glitch) and than also rotate to the rotation of the ground (like on a terrain it follows the curve of the hill)
so far I have it so that the blood is created and than is set to a height of 0.01 which works fine with a floor at a set position of 0 but if I want to move to a terrain or slanted floor, it wont work because it will be at one set height and rotation.
Any help is appreciated.
This is what I have so far.
var myx = transform.localPosition.x;
var myz = transform.localPosition.z;
var initialRot: Quaternion;
var bloodMats: Material[];
var changed = false;
var randomness = 1;
function Awake() {
transform.rotation = Quaternion.identity;
// create a random rotation around Y axis
var randomRot = Quaternion.Euler(0,Random.Range(-360, 360),0);
// combine the initial rotation with the random one:
transform.rotation = randomRot;
}
function Update() {
if (changed == false) {
var myx = transform.localPosition.x + Random.Range(-randomness,randomness);
var myz = transform.localPosition.z + Random.Range(-randomness,randomness);
transform.position = Vector3(myx,0.01,myz);
mat = Random.Range(0, bloodMats.length);
renderer.material = bloodMats[mat];
changed = true;
}
}