I’m working on an editor, where the player can move an object around the editor, snapping it to surface normal. The player can also rotate the object around its X axis. Whenever I try and snap it to the surface normal it matchs all the axis of the normal and I lose the facing that it had before the snap. I’ve tried a bunch of different things and I’ve had limited success. I’m obviously missing something.
tempX=targetObject.transform.localRotation.eulerAngles.x;
targetObject.transform.rotation = Quaternion.FromToRotation(Vector3.up, hitNormal);
targetObject.transform.Rotate(Vector3.up * -tempX);
targetObject.transform.position = mInputManager.hit.point;
I fixed your code, next time be sure and format the code, by selecting it and click the "010101" button, or just indent it four spaces...
– Seth-BergmanI'm confused.. what is it you WANT to happen?
– Seth-Bergmanso you do you not want to randomly rotate but rotate the nearest face of the object then? (his problem is basically I THINK that he ends up with an object snapping to have it with a face parallel to another. but to do so he is basically just mimicking the object and so he completely flips objects all over. He wants the minimum rotation needed to make an object have a face parallel to another) I THINK.
– sparkzbarca[9391-rotation_example.jpg|9391] So if I click on each of these points in turn, I want to snap the object to the ground and align the local y and z of the object to the normal of the surface and leave the X axis the same as it was.
– olas72is this for like a character to run up walls and stuff? basically i'm thinking your actually wanting to keep the y axis the same not the other one. x axis rotation would literally rotation the tip of the arrow through the ground or wall or whatever. rotating left and right is actually a rotaiton of the Y axis not the X.
– sparkzbarca