x


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

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 gravatar image

JonnyHilly
167 5 6 9

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

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 gravatar image

JonnyHilly
167 5 6 9

(comments are locked)
10|3000 characters needed characters left

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 gravatar image

StephanK
6k 40 53 93

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1330
x337
x62
x45

asked: Aug 05 '10 at 12:42 AM

Seen: 1887 times

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