Question by
brandonxlaw · Jan 15 at 06:16 PM ·
rotationgameobjectplane
[AR] Align rotation of object to detected plane
Hi, I am new to Unity and can't figure out how to align a placed object flat on a plane (whether vertical or horizontal).
For more context, I am trying to place a painting but as you can see, it sits perpendicular to the detected plane. When the painting is placed on the wall, it sits horizontally. How do I set it so that it will lie flat against the plane?
Also it faces away from the camera so if you can help with rotating so it faces the direction of the camera would be a great addition as well! Thank you.
Here is the code:
// First index in the s_Hits list.
var hitPos = s_Hits[0].pose;
// Check to see if we already have a spawned object in the world.
if (spawnedObject == null)
{
spawnedObject = Instantiate(placeablePrefab, hitPos.position, hitPos.rotation);
}
// Means we already have an object placed.
else
{
// Update the object's current position and rotation to the newly touched.
spawnedObject.transform.position = hitPos.position;
spawnedObject.transform.rotation = hitPos.rotation;
}
Here is what it looks like:
cleanshot-2022-01-15-at-131005.png
(482.4 kB)
Comment