# Character jumps higher when not moving horizontally

I have been using unity 4.3 and just moved over to 4.5 but I think that this has been happening for awhile and I just wasn’t paying attention.

I’m making a 2D platformer and I’m directly setting the velocity of the player character rigidbody2D to move it around. However, whenever I make the player character jump, if he is moving horizontally he won’t jump as high.

I’ve tested pretty thoroughly, and I’m pretty sure the problem isn’t in my code. I have set both the linear and angular drag of the rigidbody to 0, but it makes no difference.

I’m pulling my hair out over this. Help please.

EDIT: Relevant movement code for the character is added below. It is called during FixedUpdate.

EDIT2: I just went and tested an old build. I just recently went and moved all my velocity code into FixedUpdate, and this build was from before that. I noticed that the movement speed of the player was much higher then, even though the velocity values are much the same. What could cause that?

``````public void Move()
{
velocity = rigidbody2D.velocity;

horizontal = Input.GetAxis("Horizontal");

if(grounded)
{
if(attackTimer <= 0)
{
velocity.x -= velocity.x * Time.deltaTime * 15.0f;
velocity.x += horizontal * 15.0f * Time.deltaTime;

if(Mathf.Abs(horizontal) < flipBuffer)
{	velocity.x -= velocity.x * Time.deltaTime * 10.0f;	}

if(Stamina < MaxStamina)
{
Stamina += Time.deltaTime * StaminaRecharge;
}
}
else
{
velocity.x = 0;
}
}
else
{
if(attackTimer <= 0)
{
velocity.x += horizontal * 10.0f * Time.deltaTime;
}
}

if(jumpButtonDown && (Stamina >= 1 || grounded))
{
velocity.y += jumpStrength;
}

rigidbody2D.velocity = velocity;
}
``````

I am clamping the velocity elsewhere. The x and y of the velocity are clamped separately so that isn’t the problem.

I didn’t use GetButtonDown because I thought it might be triggering multiple times.

In any case, I’ve just added a kind of fudge factor to the movement that gives the player a little bit of lift if he is moving horizontally. It’s not the way I would prefer to do it, but it works.