I’ve been pulling my hair over this for days. I just cannot seem to get it: Look at this picture:
All I want is user to choose:
X-Axis of cube should match the Z direction of the other transform.
Z-Axis of the cube should match the Y direction of the other transform.
I’ve tried many things. I can perform the transformations individually, but cannot figure out how to do them both sequentially, the rotation just screws up. Any help is appreciated.
Okay, so if I’m following this correctly, you want ObjectA’s X direction to be ObjectB’s Z direction, and ObjectA’s Z direction to be ObjectB’s Y direction, so if ObjectA were sitting exactly on the origin and at identity rotation, and ObjectB was in exactly the same location, ObjectA would be facing “forward”, and ObjectB would be facing “right” AND rotated onto its left side? That’s a 90 degree rotation to the right along the Y axis, 90 degree rotation to the left on the Z axis, so:
Sorry I forgot to say:
X-Axis of cube should match the Z direction of the other transform.
Z-Axis of the cube should match the Y direction of the other transform.
and any other similar combinations:
i.e.
Z → Y, Y-> Z, Z → X, X → Z, X → Y, Y → X etc.
edit: The “Cube” can be in any orientation, the transform I’m trying to map the directions to is always constant.
If this isn’t a good way to go then how about changing the non-cube transforms directions to match what I wanted as Up/Forward from the user? Would that be easier?
They’re all easy. If you want to match the axis, use SetLookRotation to match it to whatever you want. The first parameter sets the “forward” direction, the second sets the “up” direction. Those are all you need to set to perfectly match up the axis for both objects.
If you want to be able to do it by passing in some sort of variable substitute, just use:
You left out a BIG piece of the code I posted. Notice that I used ObjectB.transform.TransformPoint(direction) for both parameters? You need to replace the “direction” in there, not the whole thing. You can’t make a rotation relative to another rotation without actually referencing the second rotation in any way.
Edit: You should use TransformDirection instead of TransformPoint. Since you’re using shortcut directions, it won’t make any difference at all to the result, but it will be a lot faster.
I did actually notice and add that after, exactly the same result. All that code does is make my “cube(Object B)” transform.forward face toward the forward direction of ObjectA. This isn’t really what I wanted.
I’ll try explain it a different way:
Look at the transform in the original picture (The one not attached to the cube).
I want it’s current Y to instead be in it’s Z direction and it’s current X to be in the direction it’s Y used to be. And all possible combinations of that.
Sorry for such bad explanations! I’m sure that’s not helping with solving this myself ha
Sorry, I blame the fact that I’m exhausted. Once again, ObjectA and ObjectB refer to your two GameObjects, and vectorDirectionA and B refer to those random directions that you choose with input commands.
Yup, I’m tired. I knew I was being an idiot the moment it turned into more than 2 lines to do this. I think the last one would work too, but it’s a really pointlessly roundabout way to do it. >_>;
Ok I’m sorry about this and thank you very much for your time. I’ll try to explain it better:
I’ve thought of an easier mission to achieve now anyway.
I have this transform:
And I have an cube which can have any orientation. That cube has a script on it where someone can decide:
I want your local Blue axis to point towards the camera and your local Red axis to point up.
The transform should get that info and say:
Ok, they want my local Blue axis pointing toward the camera and my local Red axis pointing up. Then do the rotation.
Then, the cube can smoothly rotate towards that point and be in the correct orientation that was decided.