Hi !
Featured games (85)
games approved by the League of Dukes
Games in Showcase (636)
Games in Android Showcase (178)
games submitted by our members
Games in WIP (687)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  [libGDX] [Box2D] Character Controller  (Read 4111 times)
0 Members and 1 Guest are viewing this topic.
Offline SrFurias

Senior Newbie

« Posted 2013-07-13 10:04:25 »

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?


P.D: I'm spanish and my English is like a Indian hahaha, thanks for try understand me.  Grin
Offline heisenbergman

JGO Coder

Medals: 14

L___ o_ G___ a__ P___

« Reply #1 - Posted 2013-07-13 10:28:00 »

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:


(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

Offline SrFurias

Senior Newbie

« Reply #2 - Posted 2013-07-13 11:19:31 »

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.  Smiley
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline heisenbergman

JGO Coder

Medals: 14

L___ o_ G___ a__ P___

« Reply #3 - Posted 2013-07-13 12:15:53 »

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 Smiley Best of luck.

Offline Jimmt
« League of Dukes »

JGO Kernel

Medals: 165
Projects: 5
Exp: 3 years

« Reply #4 - Posted 2013-07-13 13:48:39 »

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.
Offline ShuKen

Senior Devvie

Medals: 5
Projects: 1

« Reply #5 - Posted 2013-09-18 17:32:43 »

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


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?
Offline matheus23

JGO Kernel

Medals: 123
Projects: 3

You think about my Avatar right now!

« Reply #6 - Posted 2013-09-18 17:35:54 »

When you construct the BodyDef, set fixedRotation to true:

See my:
    My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
Offline ShuKen

Senior Devvie

Medals: 5
Projects: 1

« Reply #7 - Posted 2013-09-18 17:43:05 »

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):

Will be very usefull.
Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

Dwinin (70 views)
2015-11-07 13:29:08

Rems19 (80 views)
2015-10-31 01:36:56

Rems19 (72 views)
2015-10-31 01:32:37

williamwoles (106 views)
2015-10-23 10:42:59

williamwoles (92 views)
2015-10-23 10:42:45

Jervac_ (106 views)
2015-10-18 23:29:12

DarkCart (134 views)
2015-10-16 00:58:11

KaiHH (116 views)
2015-10-11 14:10:14

KaiHH (155 views)
2015-10-11 13:26:18

BurntPizza (169 views)
2015-10-08 03:11:46
Rendering resources
by Roquen
2015-11-13 14:37:59

Rendering resources
by Roquen
2015-11-13 14:36:58

Math: Resources
by Roquen
2015-10-22 07:46:10

Networking Resources
by Roquen
2015-10-16 07:12:30

Rendering resources
by Roquen
2015-10-15 07:40:48

Math: Inequality properties
by Roquen
2015-10-01 13:30:46

Math: Inequality properties
by Roquen
2015-09-30 16:06:05

HotSpot Options
by Roquen
2015-08-29 11:33:11 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!