Decal error

Hi,
I followed the spawn decal on mouse click tutorial. I used that code inside a ray cast hit. I got very strange decal spawn on hit point position. This is the ray cast code -

if(Physics.RayCast(cameraHead.Position, cameraHead.Direction, out hit, shootingRange)))
{
   var decal = Scene.AddChild<Decal>();
   decal.Position = hit.Point;
   decal.Material = baseMaterial;
   decal.Direction = hit.Normal;
}

See the attached image.


The red circle is the actual decal which I created in the editor. The decal from the code should look like it. But after ray cast the decal looks like the left image. Right image is the actual texture that I used for the decal. Any help!!

Hmm looks fine at a first glance, you might want to use DebugDraw to preview the normal vector at the hit location. It’s probably rotated by 90 degrees.

Ah the Decal is rendered from Up into Down direction so if you want to have it nicely textured at Normal then after setting it’s direction simply rotate it by 90 deg:

decal.Direction = hit.Normal;
decal.Orientation *= Quaternion.Euler(90.0f, 0, 0);

That gave me a very big headache really , did not thought that I should rotate it. Thanks.

1 Like