Match surface rotation on all axes
So, I'm trying to spawn objects on different surfaces when I click on them and match the rotation of that surface in all axes. What I have done so far is:
Instantiate(obj, hit.point, Quaternion.FromToRotation(Vector3.up,hit.normal));
However this only takes into account the Y-Axis of the object. Have a look.
The white cubes are the spawned objects. What I have is the left side. What I want to achive is the right side (rotated the cubes by hand). One thing that might be noteworthy is, the blue object has no rotation while the red plane is rotated. How would I go about doing this?
Changing Vector3.up
to hit.rigidbody.transform.up
could help.
Thanks, I tried Quaternion.FromToRotation(hit.transform.up, hit.normal)
, however this only makes things worse. See picture I also tried Quaternion.FromToRotation(obj.transform.up, hit.normal)
. This gives the same result as using Vector3.up
.
$$anonymous$$y guess is rather, that I need to look up the world rotation of the individual surface(triangle even?) that got hit if that is somehow possible, since like in the blue example surfaces might have an angle without the surfaces gameobject being rotated but rather due to the shape of the mesh. Anyone got any experience with that?
Did you check your model's pivot? Are they aligned with the model?
Your answer
Follow this Question
Related Questions
Can someone please help me out? thank you in advance! 0 Answers
DESPERATE How to align transform.up with another vector3 (direction) ? 1 Answer
Find Normal Vector to BoxCollider 0 Answers
Rotate the point around the normal from two points (flip point) 2 Answers
Wrong normals when object is rotated and using custom world aligned shader? 4 Answers