# Walking to point, wierd quaternion problem

Flasher

17-06-2012 08:33:25

Hello, folks! I'm starting to learn MOGRE (and C# for this particular reason, lol) and trying to implement simple order-based unit control (like in typical noname RTS). I have a code, based on tutorial, which turns unit in required direction and update code to move it that way.
Facing code
``` // Here Destination is Vector3 with coordinates to move and _baseNode is the node i want to move. // _destination is used to store target place inside unit object _destination = Destination - _baseNode.Position; // _distance is just a float to store... um... distance? _distance = _destination.Length; _destination.Normalise(); // Model is ogreface which faces positive UNIT_Z, so changed it from UNIT_X Quaternion _direction = (_baseNode.Orientation * Vector3.UNIT_Z).GetRotationTo(_destination); _baseNode.Rotate(_direction); _order = Action; // Nevermind, just fragment of order system ```
Update code
``` // Here I move node along it's own Z axis (facing direction) _baseNode.Translate(new Vector3(0, 0, (_moveSpeed * delta)), Node.TransformSpace.TS_LOCAL); _distance -= (_moveSpeed * delta); ```

Here is my weird problem. If i first move the node along global Z axis (for example give unit (0,0,150) target coordinates), all works well and all following commands are properly executed, node moves just as i think it should. If, however, first movement would be not along global Z, but along global X, for example (coordinates like (-200,0,0) or anything but Z), node goes crazy and turns to random point (and random coordinates) on each next order.

Now, I already solved it by a dirty hack (added Translate(Vector.UNIT_Z) to constructor) so it works as i want. But still i want to know, is it an OGRE bug, intended feature (like "node should be ... before transformations") or i just screwed up something?

-----

Ok, i found why this doesn't work xD. But the question remains. Why i can't just rotate node in some direction, and then move it along it's axis? Is it theoretically possible, or something wrong with this? (besides the fact it didn't work)