- Home /
Translate and rotate at the sametime problem
hi guys, i have a problem, i need to translate and rotate a plane at the sametime, but when i do that he change the direction and i want to go forward on the same direction (3)
1- A simple translate
2- A translate and rotate, but the direction change ;( (my current problem)
3- I want that the plane rotate 30º and hold the translation.
please, any help?!
Answer by robertbu · Mar 18, 2013 at 09:49 PM
Without seeing 1) your code, and 2) understanding the nature of the object (i.e. what position is the pivot the object rotates around), it hard to give you a definitive answer. There are a couple of things that can cause what you are seeing.
I'm going to assume that the point of rotation is in the center of the line. I'm also going to assume you are translating your object by using transform.forward for the direction. If so, the easiest fix is to use an empty game object as the parent, and the 'line' object as a child. To rotate the 'line' child, just use Transform.localRotation. The parent forward will still be in the correct direction, so the translation code uses the empty game object for its direction and position. If my assumptions here are not correct, please add more information.
your assumptions were correct i have a empty parent gameobject that make a translation and a child that make a rotation.
Parent code when pressed:
transform.Translate(new Vector3(0,0,constantSpeed*Time.deltaTime*$$anonymous$$Speed));
child code when pressed:
transform.localRotation = Quaternion.Euler(new Vector3(0, 20, 0));
but don't work, when i press to go forward the gameobject as a whole, change the direction.
I''ve converted your answer to a comment - on UA answer means solution and not reply. There's a "comment" button hidden at the right hand side.
Hi, i already solved the problem, you were right! the reason of the strange behaviour was an other thing, i am very thankful to you. :)
I'm confused. Is the behavior you want #2 above or #3 above? The code above does #3 which is what I thought you wanted. If it is #2, it is easy enough.
No you were totally right, the code that i wanted was to make the #3 behavior, and with localRotation, it worked just fine, thanks!