Implementation behind Transform.forward

I wondering what philosophy stands behind Transform.forward setter. In my opinion it should rotate coordinate system by smallest angle needed to make forward vector equal to new value. So implementation should be something like that:

class Transform
	private Vector3 _forward;

	public Vector3 forward
			Vector3 oldForward = _forward;
			Vector3 newForward = value;

			Vector3 axis = Vector3.Cross(oldForward, newForward).normalized;
			float angle = Vector3.Angle(oldForward, newForward);

			transform.rotation = transform.rotation * Quaternion.AngleAxis(angle, axis);

right? But I noticed, that Transform.forward setter works exactly in the same way as Transform.LookAt(transform.position + transform.forward).

So my question is: How does Transform.forward setter works? What happen with up and right vectors?

I found something in that post:
Efficiency of transform.forward, up, and right - Unity Answers (Bunny’s answer).

public Vector3 forward
     get { return this.rotation * Vector3.forward; }
     set { this.rotation = Quaternion.LookRotation(value); }

And now I understand why transform.forward works exactly the same as Transform.LookAt() ;D

It’s unlikely you’ll get an authoritative answer, because that would require knowledge of internal workings of Unity that the community at large won’t have. However, I doubt that it looks anything like your suggested implementation - to my knowledge, all internal rotation calculations are handled via Quaternions, not very Vector3 Euler angles.

It’s a misunderstanding of what these are. transform.forward is just a simple Vector3. It’s a length one direction vector – your personal blue arrow. It has no right or up vector. It isn’t missing. It just can’t have one.

LookAt gives a rotation/quaternion. It has an extra part. It aims down a direction, with a local z-spin (the thing which is normally set to UP.) 'LookAt` says “OK, this is a Vector3 direction that has no spin, since directions can’t even have spins. I’m going to aim this way and also make-up a spin and add it, to get a Quaternion.”

transform.forward is just an easier way to say it. its a feature that the friendly unity developers gave us that requires a couple less milliseconds time for a cpu to figure if it matters. Transform.LookAt() requests an unnessassary calculation from the game engine and your script waits for a return between TWO points. it may not matter to a lot of projects but if you had a game calculating 100 objects every frame it would matter. think of transform.forward as a shortcut.

you can do really basic stuff with out euler angles but really there is a lot of stuff you cant do without them. so you will eventually need to learn. hopefully before you end up banging your head against the keyboard trying to figure out why you cant get a script to do what you want.

actually, transform.forward is a euler angle. it’s an exact abbreviation for Quaderton.Euler(0,0,1)

as you could guess…Quaderton.Euler(0,0,-1) is backwards and so on…

eulers are actually simpler to script and some funtions you need to call rely on them!