Hi !
Featured games (84)
games approved by the League of Dukes
Games in Showcase (565)
Games in Android Showcase (151)
games submitted by our members
Games in WIP (606)
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 3098 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: 159
Projects: 4
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: 121
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.

theagentd (13 views)
2015-03-27 23:08:20

wxwsk8er (54 views)
2015-03-20 15:39:46

Fairy Tailz (47 views)
2015-03-15 21:52:20

Olo (29 views)
2015-03-13 17:51:59

Olo (30 views)
2015-03-13 17:50:51

Olo (39 views)
2015-03-13 17:50:16

Olo (44 views)
2015-03-13 17:47:07

ClaasJG (57 views)
2015-03-10 11:36:42

ClaasJG (41 views)
2015-03-10 11:33:01

Pippogeek (50 views)
2015-03-05 14:36:23
How to: JGO Wiki
by Mac70
2015-02-17 20:56:16

2D Dynamic Lighting
by ThePixelPony
2015-01-01 20:25:42

How do I start Java Game Development?
by gouessej
2014-12-27 19:41:21

Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27 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!