When my part is standing upright, LookVector is easy to get
But when my part is tilted, obviously the LookVector gets titled. But I want to know like the “pseudo” LookVector. So basically, how can I get the red arrow (so its the same as if the part wasn’t titled
The X and Z axes are shorter in length when combined with the Y. Unit-ing them will make it correct. If you multiplied a scalar with the non-unit vector, the resulting magnitude would be wrong.
You’re right. Normalizing a vector works by dividing out each axis by the vector’s magnitude. This is so the resulting magnitude of the new unit vector equates to 1. Since the Y axis was originally factored into the normalization, removing it from the equation would result in a vector whose magnitude no longer equates to 1. Do be sure to elaborate on why casting the look-vector to the XZ plane works to solve his problem
Vectors describe position as displacement. Each axis states how many units left/right, forward/backward, and up/down we must travel to reach the destination. For example, the position <-5, 2, 10> states that the object is 5 studs left of the origin, 2 studs up from the origin, and 10 studs backwards from the origin (forward is -z). Each axis is relative to the origin and not each other. It’s only when put together that they describe a point not axially locked to the origin. Your look-vector describes a vector that moves away from the origin in the direction of the forward face of your part. This also considers all cardinal directions, including up/down. You do not wish to follow vector in this direction, so we can factor it out by zero-ing the Y-axis. This is done by multiplying your look-vector by Vector3.new(1, 0, 1). The resulting vector now only tells us how to move left/right and forwards/backwards. Since each axis is not related to each other, we can trust this movement remains the same as before. All we must do now is correct the unit vector as explained in this reply
You can also look at the CFrame.lookAlong constructor as it has an UpVector parameter. You can pass it the current position and LookVector of your tilted part along with your desired UpVector.
--lookAlong(at : Vector3,direction : Vector3,up : Vector3)
local part = workspace.Part
local newUpVector = Vector3.new(0, 1, 0) -- looking up in Y
local cf = CFrame.lookAlong(part.CFrame.Position, part.CFrame.LookVector, newUpVector)
Your red arrow is drawn parallel to the ground plane (x,z), and the surface normal for that plane is likely the same as your desired UpVector (straight up). This lookAlong constructor is interesting because it should allow you to easily align your UpVector to the surface normal of a tilted ground plane too. Other than that, it would give you a whole new CFrame with LookVector equal to the one joeberson’s code would create (his is better if the vec is all you need).
If you are trying to move the part, it might be easier to put it inside of a Model. The part inside the Model can be rotated down like in the picture while the Model itself can stay aligned with the ground plane. Then you can just grab the LookVector of the Model’s CFrame when you need the psuedo lookvec.
Alternatively, you might also consider using the Edit Pivot feature in the model tab to just rotate the pivot of your part so that the pivot aligns with the ground even while the part still appears tilted (i.e. just point the facing vector in the dir you want). The PivotOffset.Orientation can also do this.