- Home /
transform.right = (point on axis) after using LookAt?
Ok, so I have been fiddling with rotations for quite a while now, and I am getting absolutely NOWHERE when it comes to using LookAt() or LookRotation().
Both of them corrupt the transform.up rotation to always intersect the y-axis. This is cool in theory, however I would rather have the transform.right always intersect the x-axis for my purposes...
Anyone have any suggestions as to how I can accomplish this?
I will include a few screenshots...
I saw in a tutorial you could set the forward of an object to equal the forward of the camera to make them look at the projection plane of the camera ins$$anonymous$$d of the camera's actual location...
So why can't I set my objects localeulerAngles.right to Vector3.right and be done with it?
point of order, localEulerAngles does not have a "right"... it SHOULD. And it should be able to be SET.
It's often easiest to just child the rotating object to an empty, spin it a bit, and then use the empty's LookAt.
Understand that we are talking about boneWeights here Louis. The block above is a basic 1x10x10 wall with 2 bones along the east and west edge. the bones are then told to LookAt() the origin. Unfortunately, the z axis is never rotated, and it leads to some weird deformation.
Answer by Cyber_Defect · Apr 27, 2013 at 08:52 PM
I used Vector3.Cross...
Vector3.Cross((Vector3.zero - bones[0].position).normalized, (Vector3.zero - bones[1].position).normalized);
That gives you the appropriate up axis. Then you use:
Quaternion.LookRotation((Vector3.zero - bones[i].position).normalized, (up vector earlier defined)).
I don't want to spell it out, but that's your bones' lookRotation ;)
Answer by robertbu · Apr 18, 2013 at 04:46 AM
I'm not sure this will work for your situation, but I'll toss the idea out anyway. You can split up your look roation into two look rotations on two separate game objects. Think tank with one rotation for the turrent, and a second rotation for the elevation of the gun barrel. You achieve the separate rotation by manipulaing the hit point. For example, for the turret, you bring the hit point down to the level of the turret before doing the the Transform.LookAt(). And for the elevation you would place the point in front of the barrel but at the correct Y height relative to the barrel. In your case, you would use an empty game object. I'm thinking that by splitting the rotation you can isolate/force the rotation around the X axis.
I was working on that same concept earlier today, because logically it sounds solid...
However I couldn't think of an eloquent way of doing it. $$anonymous$$aybe I will slap out some code and see what I can do with it.
Ok, so trying this method will not work. The z axis never gets rotated through because Y always comes first. I tried manually setting the X axis first, but it still jumps to the Y axis before hitting the Z.
It was a decent effort though :(