Movement on the X an Z axis are combined?

Posted by Magicaxis on Game Development See other posts from Game Development or by Magicaxis
Published on 2012-10-28T12:23:38Z Indexed on 2012/10/28 17:19 UTC
Read the original article Hit count: 198

Filed under:
|
|
|

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?

© Game Development or respective owner

Related posts about XNA

Related posts about c#