- Home /
Question by
SVGK · May 03, 2014 at 10:52 AM ·
rotationorientation
Change the default rotation of a quad?.
Hello, I need a quad, or something else that can act a similar way, like the cursor aim in Pikmin 3, the cursor there can be seen on that glass wall, however, there is a slight problem in my case, quads are oriented at the wrong angle, so my code isn't working right.
Ray OriginRay = theCamera.ScreenPointToRay (Input.mousePosition);
RaycastHit OriginRayHit;
if (Physics.Raycast (OriginRay, out OriginRayHit, Mathf.Infinity))
{
crossHair.transform.rotation = Quaternion.FromToRotation (Vector3.up, OriginRayHit.normal);
crossHair.transform.position = OriginRayHit.point + (OriginRayHit.normal * 0.03f);
theDistance = Mathf.Sqrt (OriginRayHit.distance) * 0.15f;
aimSizer = new Vector3 (theDistance, theDistance, theDistance);
crossHair.transform.localScale = aimSizer;
}
See, I need the quad to be oriented flat against any object it's on, but due to the nature of quads orientation, should I just make a flat face in Blender?, is there some trick I haven't heard of?.
Comment
Best Answer
Answer by robertbu · May 03, 2014 at 01:06 PM
If you are using Unity's Quad and you want to align that Quad with the surface normal, then line 6 needs to change. Change it to:
crossHair.transform.rotation = Quaternion.FromToRotation (-Vector3.forward, OriginRayHit.normal);