Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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];
    block.CopyAbsoluteBoneTransformsTo(transforms);
    // 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.EnableDefaultLighting();
            effect.World = transforms[mesh.ParentBone.Index] *
                Matrix.CreateRotationY(MathHelper.ToRadians(mOrientation.Y))
                * Matrix.CreateTranslation(mPosition);
            effect.View = game1.getView();
            effect.Projection = game1.getProjection();
        }
        // Draw the mesh, using the effects set above.
        mesh.Draw();
    }

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?

share|improve this question
    
I guess your matrix usage is incorrect. –  Nick Wiggill Oct 28 '12 at 13:04
    
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. –  RobCurr Feb 25 '13 at 19:16
    
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 –  Magicaxis Feb 25 '13 at 21:19

1 Answer 1

First..

you can set the translation of matrix easily...

Transform.Translation = yourTranslation;

Second...

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...

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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