# how do I change the height of my plane to the height and rotation of the object beneath it?

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;
}

}
``````

If you want to get a spatter in the direction of the bullet hit on a wall or ground what you could do is use a raycast from the player position using the trajectory of the bullet to get a raycast hit on the ground or wall. From this raycast hit on the ground/wall you can get all kinds of information that you could use to do what you need.

RaycastHit: Unity - Scripting API: RaycastHit

If you want to have the blood splatter only on the ground you can use the player collider to get the ground and use the same information from the collision.contacts[0] to get the normal, etc… or just shoot a raycast downward to hit the ground and use the above stated method.

Collision: Unity - Scripting API: Collision

Edit: You would use the collision normal or do some vector arithmetic to get the angle of the ground. I believe this will get the information you need.

thanks for the reply, I will try to use that. I also read somewhere about decals? could these possibly be used to make blood splats on the floor and surrounding walls? if so how do I go about implementing them?
again thanks.