# Moving Character in C# XNA Not working

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)
{
JumpInput();
MoveInput();
}
private void MoveInput()
{
//Move Character right
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);
}
}


}

• 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? Jun 20, 2012 at 14:30
• 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. Jun 20, 2012 at 14:32
• Start with a known good example. This question is too localized to your code for it to help anyone else in the future.
– House
Jun 20, 2012 at 14:34
• 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 Jun 20, 2012 at 14:37
• 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.
– House
Jun 20, 2012 at 14:53

Vector2 velocity = new Vector2(0,0);