Local direction problem. Setting the rotation of a object relative to its parent.

Hello there.

I have a simple object (transform var turbine), and i want it to smoothly face local directions, as it’s a child of the “jet” transform.
Here is the piece of code (attached to its parent “jet”):

But it doesn’t work.

Can someone help?

Also, is -Vector3.up the inverse of its absolute? I mean, live Vector3.down?

Thanks.

I’m not sure what you’re trying to do exactly, but it might be Transform.localRotation that you want to be modifying, rather than Transform.rotation.

Also, this:

Quaternion.LookRotation(transform.up)

Is likely to produce invalid results (since the input vector is parallel to the default reference vector).

-Vector3.up is the ‘opposite’ of Vector3.up, yes.

What i’m trying to do is quite simple:

There are 3 directions possible for the “turbine” transform that is child of the “jet” transform. The directions are relative to it’s parent. I want to set these directions. But nothing that i’ve tried work.

Thank you.

449484--15671--$jetty.jpg

I made some suggestions earlier - did those make any difference? If you changed your code at all, can you post the revised code?

Yes, your tip actually helped a lot. I was able to write a piece of code that actually works:

function TurnRight () {
turbine.localRotation = Quaternion.Slerp(turbine.localRotation, Quaternion(0,0,0.7,-1), 0.1);
}

function TurnLeft () {
turbine.localRotation = Quaternion.Slerp(turbine.localRotation, Quaternion(0,0,0.7,1), 0.1);
}

function Center(){
turbine.localRotation = Quaternion.Slerp(turbine.localRotation, Quaternion(0,0,0,1), 0.1);
}

However, I don’t know if it’s “okay” to use it because it’s pretty confusing and Unity manual said that it isn’t a good thing to manipulate quaternions.

Thank you.

Yeah, constructing the quaternions manually like that probably isn’t what you want to do. For one thing, the first two quaternions there aren’t unit-length (although the end result will likely be unit-length, as Unity generally keeps quaternions normalized ‘under the hood’). Also, although sometimes constructing a quaternion manually can produce sort-of-intuitive results, keep in mind that the elements of a rotation quaternion are not angles. (You can however use Quaternion.Euler() to create a quaternion from a set of Euler angles.)

turbine.localRotation = Quaternion.Slerp(turbine.localRotation, Quaternion.Euler(0,0,75), 0.1);

SOLVED.

Thank you very much Jesse Anders!