Rotating object while rounding off local Y axis.
First of all, sorry in advance because this question has probably been asked before I have been unable to find a solution that works for me because of the fairly specific case.
So I'm trying to get an object to 'snap' to another object. The first object should copy the other object's rotation, except that the local up axis should also 'snap' to the nearest 90 degrees (relatively, so that the two objects will always have a square angle), so that it can snap in four different ways.
What I did before was:
Vector3 relativeRotation = standStillObject.transform.rotation.eulerAngles - approachingObject.transform.rotation.eulerAngles;
relativeRotation = new Vector3(relativeRotation.x ((int)Math.Round(relativeRotation.y / 90.0)) * 90, relativeRotation.z);
approachingObject.transform.rotation = Quaternion.Euler(standStillObject.rotation.eulerAngles - relativeRotation);
However, the problem with this approach is that the rotation is rounded off over global y, not local up and I have no idea how to change that.
Any help is very much appreciated.
Your answer
Follow this Question
Related Questions
If rotation was over 20° smoothly rotate towards the next 90° 2 Answers
More problems with arrow shooting 0 Answers
Mobile Gyroscope, make Camera always rotating towards zero point using Quaternion 2 Answers
Using a directional vector to orient a sphere? 0 Answers
Quaternion AngleAxis on pitch give random small value on others axis 0 Answers