I'm having trouble trying to get my character to move for a game I'm making in my sparetime for the Xbox. However, I can't seem to figure out what I'm doing wrong , and I'm not even sure if I'm doing it right. I've tried googling tutorials on this but I haven't found any helpful ones. Mainly, ones on 3d rotation on the XNA creators club website.

My question is : How can I get the character to walk towards the right in the MoveInput() function? What am I doing wrong? Did I code it wrong?

The problem is : The player isn't moving. I think the MoveInput() class isn't working.

Here's my code from my character class :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace Jumping
class Character
    Texture2D texture;
    Vector2 position;
    Vector2 velocity;
    int velocityXspeed = 2;
    bool jumping;

    public Character(Texture2D newTexture, Vector2 newPosition)
        texture = newTexture;
        position = newPosition;
        jumping = true;
    public void Update(GameTime gameTime)
    private void MoveInput()
        //Move Character right 
        GamePadState gamePad1 = GamePad.GetState(PlayerIndex.One);
        velocity.X = velocity.X + (velocityXspeed * gamePad1.ThumbSticks.Right.X);

    private void JumpInput()
        position += velocity;

        if (GamePad.GetState(PlayerIndex.One).Buttons.A == ButtonState.Pressed && jumping == false)
            position.Y -= 1f;
            velocity.Y = -5f;
            jumping = true;

        if (jumping == true)
            float i = 1.6f;
            velocity.Y += 0.15f * i;

        if (position.Y + texture.Height >= 1000)
            jumping = false;

        if (jumping == false)
            velocity.Y = 0f;
    public void Draw(SpriteBatch spriteBatch)
        spriteBatch.Draw(texture, position, Color.White);


  • 1
    \$\begingroup\$ What have you done to debug this so far, what have you tried? Does Position actually work if you directly put different numbers, what are your joypad read values, logged velocities and positions, are these routines actually getting called? \$\endgroup\$ – Patrick Hughes Jun 20 '12 at 14:30
  • \$\begingroup\$ The function is being called in the Main Class file update under Player.Update, and the update in the Character class (this class), is calling MoveInput(). But for some odd reason the character isn't walking across the screen. \$\endgroup\$ – Monstr92 Jun 20 '12 at 14:32
  • \$\begingroup\$ Start with a known good example. This question is too localized to your code for it to help anyone else in the future. \$\endgroup\$ – MichaelHouse Jun 20 '12 at 14:34
  • \$\begingroup\$ I'll keep that in mind for future questions! I just solved the riddle thanks to your suggestion Vector2 velocity = new Vector2(0,0); ! :3 \$\endgroup\$ – Monstr92 Jun 20 '12 at 14:37
  • \$\begingroup\$ Sure thing Matthew. Do remember to include more information in your future questions. Explain exactly what the problem is, tell us what you've tried and what about your attempts to solve it didn't work. \$\endgroup\$ – MichaelHouse Jun 20 '12 at 14:53

Though you haven't told us what the problem is. I can see that you never initialize your velocity variable.

Vector2 velocity = new Vector2(0,0);

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.