How do i instantiate a prefab with the z axis facing down

On my instantiated object i want:

Y: to be facing away from the hit normal ( which i have working now)
and X: To be facing down in global coordinates, so it points the way gravity it pulling

emptycopy=Instantiate(empty,hit.point,Quaternion.FromToRotation (Vector3.up,hit.normal));
		
		emptycopy.rotation.x=90;

This doesn’t work because i think its rotating the X in local space and not global,How do i get the X to point downward

This might seem crazy, but you could try parenting it to an empty GO, with the axis how you want it, then when it instantiates, unparent it in the awake call? Or just use timed object destructor script with a quick detatch and destroy setting?

Ugly hacks are my specialty, but they certainly arent pretty.

:stuck_out_tongue:

AC

Have you considered using the Transform object’s LookAt function? You could build the right target transform to look at, then use hit.normal for the world-up reference and that should do what you’re looking for.

Edit: quick-and-dirty forum code example (untested!):

// instantiate a copy of 'empty'
emptycopy = Instantiate(empty, hit.point, Quaternion.identity);

// initialize the target position to look at
var targetposn = hit.point + gravitydirn;

// look at the target position, aligning the y-axis against the hit normal (pointing away from)
emptycopy.transform.LookAt(targetposn, -hit.normal);