2d character horizontal movement

Hello all,

I have implemented horizontal movement for my player by the following:

float move = Input.GetAxis ("Horizontal");
rigidbody2D.velocity = new Vector2 (move * maxSpeed, rigidbody2D.velocity.y);

This works fine, but if horizontal movement is constantly applied against a “wall” and then the player jumps (with AddForce function), the player can then jump up the wall. I tried:

rigidbody2D.AddForce(new Vector2(move * maxSpeed, rigidbody2D.velocity.y));

but the friction of the “floor” stops the player from moving. Any assistance appreciated!

I’m not ENTIRELY sure what you mean by jump Up the wall, but i think you’re saying that the user can press jump repeatedly as long as they’re touching a wall, and they’ll keep going up, right?

If so, it sounds like your code is only checking whether the player is touching any surface, rather than if they’re specifically touching a floor. You’ll need some more advanced checking of collisions to determine where the surface is, relative to the player. Or perhaps just use the tagging system if your game is simple enough, you could tag certain parts as floor, some as Wall, and use the tags to differentiate between them.