Setting rotation parallel to ground

I’m making a game where you graffiti on walls. My current code aligns the instantiated decal to the normal of the object being sprayed on, however often it appears upside-down or sideways, so I want to make it align to the ground so it is facing ‘up’. I also want to add functionality to rotate the graffiti around the normal by moving the mouse left and right, but my priority is making it appear the right way up.

function Spray()
	 var hit: RaycastHit;
	 if (Physics.Raycast(transform.position, transform.forward, hit))
	 	if (hit.transform.tag == "Surface")
	 		var rot = Quaternion.FromToRotation(Vector3.up, hit.normal);
	 		gernz = Instantiate(tagged,hit.point+(hit.normal*0.0001),rot);

alt text

Shocked. Graffiti on walls? Next thing you know they’ll be writing a game about stealing cars! :wink:

Untested, but if you are writing on walls (or mostly vertical surfaces) you can do:

  • Use a Quad (or a Sprite) for the graffiti texture.
  • Replace line 9 with the following line of code:

 var rot = Quaternion.LookRotation(-hit.normal);