# How can I add left and right movement to my sprite without reducing forward movement?

I've made a character sprite that moves left and right when I press A and D, and moves forward automatically. However, whenever the character moves left or right, the forward movement is greatly reduced. Does anyone know a solution?

Here is my blueprint

• I can't say for certain because I can't test it right now but your left / right movement is going directly to the pawn but the forward movement is going to the pawn movement component. What happens if you change the left / right to go to the movement component? – Stephen Sep 3 '18 at 7:57

When you hit the arrow keys, you are traveling the same speed, but you are pointing the sprite in a different direction. The sprite's movement is based on what direction the sprite is pointing, not a fixed direction on your screen. So your sprite is still moving forwards at the same speed, but forwards the direction it is pointing, not forwards along a certain axis on the screen.

Imagine you are driving a car down a street at a certain speed. You then steer to the left. Your car is still going the same speed forwards in the direction the car is pointing, but the distance you go down the road while steering will be less. That's because your car is spending more time traveling sideways to the street than longways down the street.

You could get all fancy and do vector math to speed up the sprite to keep forwards motion the same when turning, but it is a lot easier if you just calculate X and Y offsets yourself and not rely on vectors.

Assuming that X is side to side, and Y is forwards, it would be something like this in pseudo-code.

// dx is how fast you are moving side to side.  Initially zero, so no movement
dx = 0;
// dy is how fast you are moving forwards
dy = 1;

// Main game loop
while (true) {
if (left_arrow_down) {
// Left arrow down so move left
dx = -1;
} else if (right_arrow_down) {
// Right arrow down so move right
dx = 1;
} else {
// No arrow down so just move forwards
dx = 0;
}

// Move sprite based on current arrow keys and forwards motion
sprite_x = sprite_x + dx;
sprite_y = sprite_y + dy;

// Now redraw the sprite at this  new location
draw_sprite(sprite_x, sprite_y);
}


With this kind of approach, any side to side motion will not slow down the forwards motion. Sorry I don't know Unreal enough to create a blueprint for this, but you should be able to translate this concept into a blueprint.

Try summing everything in a tick event.