# 2D character movement

My character moves right and left correctly, I want to know if it is possible to move character forward and backward to collect hearts (I know that in 2d no z axis I want to know if it is possible or not? )

There are definitley ways of accomplishing this without altering actual position of the character but instead making it appear that way.

For instance : You could try adding animations that show the character walking forward and backward (toward/away from screen) and scale his size to make it look like he is moving in the z axis.

• scaling his size to make it look like he is moving in the z axis during forward and backward only? @Gav – Sh.Adel Dec 3 '18 at 11:37
• Yup, let me know if it works for you – Gav Dec 3 '18 at 21:26
• I made animations (moving forward and backward) and tried to scale it on script if player clicked up arrow decrease the scale of y play downward animation, and if clicked down arrow increase the scale of y and play forward animation .but my problem now detecting collision (normal size of player's collider detect collision of near and far hearts without needing to move forward and backward) – Sh.Adel Dec 4 '18 at 6:49
• I changed position on script like scale and it works. thanks – Sh.Adel Dec 4 '18 at 9:03

Giving the illusion that there's a 3rd dimension has always been used on video games. It can be as simple or as complicated as you like, depending how you'd like the final result to look like.

In your case for example, you can move the character up/down using the Y-axis, to simulate that the character moves "back and forth". As long as the character interacts properly with the environment (in your case, picking up hearts when moving on the same plane as them) the illusion will not be noticed.

One example being Streets of Rage, which didn't even have an animation for moving up and down (it was just using the walk left/right one) and it made a very nice illusion. The character interacts perfectly with objects on the same plane as them, forcing the player to simulate this as 3D while they play.

You can of course change the scaling of the character as well, making them smaller as they move upwards, and bigger as they move downwards. This adds complexity, but gives a more realistic effect.

You can always add more complexity to add realism, but at the end of the day, it depends on the style you want your game to have. There is no wrong or right solution.