[libGDX] [Box2D] Character Controller

Hi, I was per days tryin do a realistic player movement, so, I have a Player (it’s a Rectangle done with bodys, bodyDefs, etc) and I need dot if I use W A S D the player do a realistic movement, or jump if case is W.

So, I has experimented too much, but I can’t get a realistic player movement…¿How can I move my player with realistic movement and jump with libGDX and Box2D?

Thanks.

P.D: I’m spanish and my English is like a Indian hahaha, thanks for try understand me. ;D

Speaking from very very recent experience, trying to do realistic movement (I assume you’re making a platformer) and still making the controls feel tight and fun is very tricky.

But in any case, if you want to continue pursuing trying to implement realistic physics in your game, the methods you’re probably interested in are:

applyForce()
applyLinearImpulse()

(and maybe set the world’s gravity to -9.8 so that you can think in terms of real-world physics)

I’m not sure that’s what you’re asking for. If you’re asking for something else, do clarify :wink:

Thanks for reply.

Yes, I’m doing a platformer game, so, I always use setLinearVelocity() methods, but now I will try to use these methods.

I will keep you informed. :slight_smile:

For what it’s worth, I started out using a lot of applyForce() and applyLinearImpulse() in my game and then just recently tweaked the controls by using setLinearVelocity() in some cases instead. As a result, the controls feel significantly tighter now.

But of course, it all depends on how you implement the physics/use the methods :slight_smile: Best of luck.

applyLinearImpulse() is not always a good choice for this. As it’s a 2d game, I usually find setLinearVelocity() more useful. Then you don’t have to wait for your character to accelerate/slow down when using WASD, it pops straight to moving.

Guys I have the same problem. First of all…how do you prevent rotating? The player fixture its a rectangle and his angle must remaing intact (zero ¿?). Tried with:

body.setAngularDamping(0f);

But it doesn’t work. The only way that I found was setting the density of the fixture to 0. ¿That’s the right way?

When you construct the BodyDef, set fixedRotation to true:

http://libgdx.l33tlabs.org/docs/api/com/badlogic/gdx/physics/box2d/BodyDef.html#fixedRotation

Damn I knew it! The javadoc description is “Set this body to have fixed rotation. This causes the mass to be reset.” WTF

Thanks for the reply, it works!.

Also found this (one min ago): http://www.badlogicgames.com/wordpress/?p=2017

Will be very usefull.