# changing transform of an object (without using "look at")

 0 ok I have an object I want to align with the terrain surface... (lets say its an arrow pointing nowrth-west) I have the terrain surface normal... and if I assign this to the arrow's up component of its transform, it correctly hugs the surface... but... it doesnt face north west anymore... why ? arrow.transform.up = surfaceNormal; why does changing the arrow's up affect its facign direction... it shouldn't unless when I change the UP... unity also resets the forward and right. I would expect it to just orthonormalize them. does anyone have an explanation for this ? or a better wat to set the UP part of a transform, but still maintain the forward vector ? thx more ▼ asked Aug 05 '10 at 12:42 AM JonnyHilly 167 ● 4 ● 6 ● 9 add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

 0 thanks muchly, that did the trick... here is the final code //first calc forward vector, using surface normal, and player's right vector (to maintain facing direction) Vector3 forwd = Vector3.Cross(playerRight ,terrainNormal ); //then calc the player's new rotation quat transform.rotation = Quaternion.LookRotation(forwd, terrainNormal); more ▼ answered Aug 09 '10 at 06:53 AM JonnyHilly 167 ● 4 ● 6 ● 9 add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users
 0 Setting the up/right/forward vector of a transform is never a good idea as this will almost always mess up at least one of the other 2 vectors. Althoug I agree with you that it would be nice if Unity would leave the other two axes untouched this isn't how it works. What you will have to use is Quaternion.LookRotation(transform.forward, yourNormal). more ▼ answered Aug 05 '10 at 09:16 AM StephanK 6k ● 39 ● 53 ● 93 add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

By Email:

Topics:

x1283
x329
x59
x43

asked: Aug 05 '10 at 12:42 AM

Seen: 1829 times

Last Updated: Aug 05 '10 at 12:42 AM