- Home /
Rotation of object/model without effecting direction C#
What's good Unity community? I've worked on Unity for over a year now but this is my first question ever, and it's my pleasure to join this community.
I'm trying to rotate a war tank in the same manner as in (Battle City - NES) where the tank rotates but controls stay the same all time, I'll explain what I mean. What I want is rotating while keeping controls the same (i.e. key "w" for north, "s" for south...etc.).
What is happening my game, however, is normal kind of rotation and transformation of the whole object, including it's direction, and thus if I rotate from north to, let's say east, then the tank faces east, but now key "w" moves it towards east, since it's the direction the tank is facing.
In other words, I want to maintain movement direction to be always W,A,S,D as for NORTH, WEST, SOUTH, EAST respectively, while rotating the model in these direction.
Many thanks in advance.
Answer by xortrox · Apr 22, 2014 at 08:53 PM
Use Vector3.left/right/up/down/forward/back instead of the transform's right/up/forward to move the tank. (I only assume this would fix it as I haven't seen any of your code yet)
Thanks for your help.
I actually solved this by having the tank in an empty object as parent. Then use the parent for movement, and the child tank object for rotation. The way to rotate this child is by looking at the parent's "forward" and "right". This way, the parent (empty object) stays in the same orientation all the time while the child tank rotates inside.
Answer by ToxxicSin · Apr 23, 2014 at 02:40 AM
If I understand correctly, when you want is a topdown view of your tank, like an arcade game, where it faces whichever direction you are traveling. Instead of just having the tank, make a parent object named "tank" (or whichever name you prefer), and then put the actual sprite itself inside the parent object. Then, when you move, you move the parent object, and when you rotate, you rotate the sprite child.
Your answer
![](https://koobas.hobune.stream/wayback/20220613143335im_/https://answers.unity.com/themes/thub/images/avi.jpg)