Hello everyone!
I’ve been going at this for a while and finally decided to take it here to hopefully have it resolved.
I have an object that is a child of the camera, but i want it to always face the camera directly based off where it is on screen. There are 2 points on the object that i want to line up with the camera, so ultimately, the camera would be the third point.
I understand that the object is never altering rotation because its a child object, but the goal is to have the object always face the camera, so dynamic rotation i guess? based off where it is and those points on the object.
I’ve included this link to
a picture i threw together in photoshop.
Any ideas? I’m still thinking of a formula to add up all these vectors, then rotate.
Actually maybe i should put it in the lateupdate function?
I’m at a stand still and any help is appreciated!
I appreciate your effort to do the drawing but I must confess I don’t understand what you’re trying to do.
Any child object can certainly be rotated, and that is exactly what the .localRotation property of the Transform component does.
You can always use the .LookAt() method on a Transform to point the +Z vector axis of a Transform towards some point in space, regardless of parentage.
I also can’t make heads nor tails from the drwing. Perhaps include the following:
- the camera, it’s up direction and where it is looking to
- the object you want to position
- the two points on the object
- (separate sketch) what you want to see on screen
From what you describe, the issue seems fairly basic. If somethng is always facing the camera, it would simply remain a daughter of the camera object, and never gets rotated.
In the meantime, you may also want to look up Billboards in unity. They always face the camera (unless you are in VR, then there is an ugly bug in most of them because shader programmers think they are smart, when in reality they are only crafty
)
To further explain: those red dots are on the same object.
Every kind of object I’ll be using wont have the same initial direction so I’ll need to use this system. So the initial direction of the object doesn’t matter. Its like I’ll be determining where the object is facing by using those 2 points. Then use that ‘new direction’ to then point at the camera. Essentially lining up those points to be on the same 2 axis with the camera.
And the reason why I need a Seperate system to handle it is so I can reposition the object in runtime and not worry about the rotation be janky. It’ll always correct itself.
Do you mean the red dots are essentially “alignment registration guides” that tell you how to rotate each object so that it is aligned correctly for viewing?
If so, you do need at least the notion of these dots being different, otherwise there will always be two solutions, one for each direction.
Assuming two dots, A and B, and you want them to be aligned with 1 and 2, this sort of inverse transform is generally handled in four discrete steps:
-
find the offset from A to world ZERO (0,0), add this offset to BOTH the A and B points (this translates to origin)
-
find the ratio of the distance from A to B versus the distance from 1 to 2, and scale the B dot position by this amount (this sets scale)
-
find the difference in the angle between A->B and 1->2 and rotate B around A until by that difference (this rotates)
-
find the offset from A (at world ZERO) to point 1, move A and B by this amount (final translate into place)
If you’re doing something else, I still don’t understand what that is exactly.
I think I understand what your getting at. I don’t get why your adding another point to it though.
There would be 2 points for alignment on the object I want to point at the camera. And then that third point would be the camera. 3 points in total. Basically just lining up those first 2 points on two axis to the third point.