- Home /
Question by
username707 · Jul 20, 2013 at 07:19 PM ·
textureterraindecal
How to add decals to terrain texture?
as above
Comment
Answer by aldonaletto · Jul 20, 2013 at 07:57 PM
If it's the standard Unity terrain, it's better to create a plane with the desired decal and place it slightly in front of the point it should appear. A common case is when you shot with raycast and want to place a bullet hole where the target was hit (weapon script):
var holeDecal: GameObject;
function Update(){
if (Input.GetButtonDown("Fire1")){
var hit: RaycastHit;
if (Physics.Raycast(transform.position, transform.forward, hit)){
// calculate rotation to align decal's up direction to the surface normal:
var rot = Quaternion.FromToRotation(Vector3.up, hit.normal);
// calculate position a little ahead the hit point:
var pos = hit.point + 0.001 * hit.normal;
// create the hole decal:
Instantiate(holeDecal, pos, rot);
}
}
}