- Home /
2D - no gravity when player jumps against wall?
Hello,
I made a 2D Jump'n'run but have a little problem: When the player jumps against a other solid cube collider (like a invisible wall - the border for the level - or the side of a platform) it just stays in the air as long as the player keeps moving in that direction. I use the standard gravity from unity and this is the movement script: rigidbody.velocity = new Vector3(moveSpeed * Input.GetAxis("Horizontal"), rigidbody.velocity.y, rigidbody.velocity.z);
I directly set the velocity instead of using AddForce because the latter of whom doesn't work that well when using standard gravity in 2D (the player sprite -cube collider- slows down hardly on the ground -more cube collider- while the player is to fast in the air).
The problem is that the horizontal collision between those colliders slows down the vertical velocity. I tried to use rigidbody.velocity = new Vector3... when the player horizontally collides with a wall but that doesn't fit because it isn't as smooth as the natural gravity.
Does anyone have another idea to solve this?
In the 2D tutorial you can see the character get stuck on the wall just like you explained and I also have this problem.
Answer by robertbu · Aug 27, 2013 at 04:29 PM
I suspect you have not setup the Physic material on the colliders. If not:
You can get a sample set of Physic Materials by Assets>Import Package>Physic Materials.
Click on 'target' symbol opposite the 'Material' label on each Collider. Select a material. Start with Ice to get things to slide.
Note you can create your own Physic materials with the specific properties you need for your game.
Thanks! That was easier than expected and works great!
Answer by xandermacleod · Nov 21, 2013 at 03:05 PM
Im having this problem although my issue is that the wall object is a floating platform that needs to rotate. (Think of a moving platform in Mario, but it rotates at certain points).
I have setup my square platform so that it has 4 separate custom colliders (1 per platform edge, that doesnt touch the other edges), so that I can have icy-walls but a normal top (so that the hero can run along it without it being slippery).
But the moment my platform rotates, if the player jumps into one of the sharp corners, he sticks in place in the same way.
Any advice?
Your answer
![](https://koobas.hobune.stream/wayback/20220613113053im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How do I “freeze” an object after a collision? 3 Answers
How to get movable/pushable cubes right? 0 Answers
Spline Interpolator + FPS Walker? 0 Answers