- Home /
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!
Answer by Nanako · Oct 23, 2014 at 03:54 AM
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.
Yes that is correct. Tried to describe it best I can. Okay I'll just do that, wasn't too sure if there was an easier fix or work around. Thanks
fyi also I found a good solution was to set the friction of the wall to 0
Your answer
Follow this Question
Related Questions
2D Box Colliders Overlapping On Collision 4 Answers
How to move a rigidbody2D at a constant speed without AddForce? 1 Answer
Rigidbody2D character movement problem 0 Answers
Drag Object Script Problem 2 Answers