- Home /
Rotating a player object without rotating the axis
Hello,
is it possible to rotate an object without changing the axis? I have a helicopter gunship that I want to pitch and roll as it moves forwards/backwards and strafes side to side, but I am not sure how to do this without affecting the axis that it translates/rotates with...
So in essence, lock the movement/rotation axis but rotate the object itself
I cannot completely visualize the problem you are trying to solve, but I believe you can get what you want by making the visible object a child of an empty game object. You would pitch and roll the visible object, but the parent object would be used for movement.
So for example, when moving forward, the gunship would pitch forward, which would mean it would need to rotate forward on the x-axis. however it translates on the z-axis which would now be angled down, which is not what I want. So would the suggestion you are making solve that? It sounds like it might, just wondering if there isn't a code way of doing it also
The solution I outlined will work. You could also simply remove the 'y' component of the forward vector if forward movement is the only issue.
Vector3 fwd = transform.forward;
fwd.y = 0.0f;
fwd.Normalize();
And use 'fwd' for your movement.
I will try your initial solution! Thank you for the help! :)