This is probably a stupid question, but I'm trying to simply move a 3D object up, down, left, and right (Not forward or backward).

The Y axis works fine, but when I increment the object's X position, the object moves BOTH right and backwards! when I decrement X, left and forwards!

setPosition(getPosition().X + 2/*times deltatime*/, getPosition().Y, getPosition().Z);

I was astonished that XNA doesnt have its own setPosition function, so I made a parent class for all objects with a setPosition and Draw function. Setposition simply edits a variable "mPosition" and passes it to the common draw function:

    // Copy any parent transforms.
    Matrix[] transforms = new Matrix[block.Bones.Count];
    // Draw the model. A model can have multiple meshes, so loop.
    foreach (ModelMesh mesh in block.Meshes)
        // This is where the mesh orientation is set, as well 
        // as our camera and projection.
        foreach (BasicEffect effect in mesh.Effects)
            effect.World = transforms[mesh.ParentBone.Index] *
                * Matrix.CreateTranslation(mPosition);
            effect.View = game1.getView();
            effect.Projection = game1.getProjection();
        // Draw the mesh, using the effects set above.

I tried to work it out by attempting to increment and decrement the Z axis, but nothing happens?! So using the X axis changes the objects x and z axis', but changing the Z does nothing. Great. So how do I seperate the X and Z axis movement?

  • \$\begingroup\$ I guess your matrix usage is incorrect. \$\endgroup\$ – Engineer Oct 28 '12 at 13:04
  • \$\begingroup\$ I am hoping that you already figured this out on your own but if not then could you please indicate what projection you are using, as well as what the value is for the mOrientation.Y. \$\endgroup\$ – RobCurr Feb 25 '13 at 19:16
  • \$\begingroup\$ The problem was elsewhere in the code. A really, really dumb error on my part in a different file. Brace yourself, I wrote this: x = getPosition.x y = getPosition.y z = getPosition.x \$\endgroup\$ – Magicaxis Feb 25 '13 at 21:19


you can set the translation of matrix easily...

Transform.Translation = yourTranslation;


I would render the axis base to see if it´s moving right.. because of your parent rotation or your camera view the behaviuor described maybe is right...

  • \$\begingroup\$ In what library is "Transform"? It's not in any namespace i'm using :( \$\endgroup\$ – Magicaxis Oct 29 '12 at 12:34
  • \$\begingroup\$ Pretty sure that's just a typo - I think he means transforms.Translation. \$\endgroup\$ – Fibericon Oct 29 '12 at 14:39
  • \$\begingroup\$ Matrix type has a translation property \$\endgroup\$ – Blau Oct 29 '12 at 14:47
  • \$\begingroup\$ Not in matrix, nor any other library, is there transform.translation. I've vhecked the axis and they are correct. \$\endgroup\$ – Magicaxis Oct 31 '12 at 13:28
  • \$\begingroup\$ msdn.microsoft.com/en-us/library/… \$\endgroup\$ – Blau Oct 31 '12 at 16:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.