Hi all,
I'm using Box2D for my platform game. Everything works well except for when the character is on a slope. I can't seem to stop the body from sliding down the slope when the character is stationary on a slope.
Has anyone had any luck with this? I've been mining google with no luck yet.
Comments
From guiders ref I -> gravityScale: (number) Scale the gravity applied to this body.
b2.Body:setGravityScale(scale)
might work for you
The problem with the gravity scale is that if you then touch say left and the character begins to run down hill, he sort of hovers in the air until enough gravity has built up to push him back down to the slope.
Unless I've got something wrong.
The next thing I'll try is applying my own gravity each frame, which can then be turned off by setting the y factor in the setLinearVelocity
Found something like that, not lua but its very easy to adopt.
The solution is a bit ugly but it seems to work...
can you try setLinearDamping with very high value when you want to freeze the character and reset it when you want to move
Likes: Tom2012
That solved the problem.
It's so funny when you find the solution and it's so straight forward. I must have spent hours fiddling around with code.
Much appreciated. :-)