Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (476)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (532)
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 1877 times)
0 Members and 1 Guest are viewing this topic.
Offline SrFurias

Senior Newbie





« Posted 2013-07-13 12: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?


Thanks.

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

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

Offline SrFurias

Senior Newbie





« Reply #2 - Posted 2013-07-13 13: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 14: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.

Online Jimmt
« League of Dukes »

JGO Kernel


Medals: 128
Projects: 4
Exp: 3 years



« Reply #4 - Posted 2013-07-13 15: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

Junior Member


Medals: 4



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

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:

1  
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?
Online matheus23

JGO Kernel


Medals: 106
Projects: 3


You think about my Avatar right now!


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

When you construct the BodyDef, set fixedRotation to true:

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

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

Junior Member


Medals: 4



« Reply #7 - Posted 2013-09-18 19: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): http://www.badlogicgames.com/wordpress/?p=2017

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

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

pw (17 views)
2014-07-24 01:59:36

Riven (17 views)
2014-07-23 21:16:32

Riven (14 views)
2014-07-23 21:07:15

Riven (17 views)
2014-07-23 20:56:16

ctomni231 (45 views)
2014-07-18 06:55:21

Zero Volt (40 views)
2014-07-17 23:47:54

danieldean (32 views)
2014-07-17 23:41:23

MustardPeter (36 views)
2014-07-16 23:30:00

Cero (51 views)
2014-07-16 00:42:17

Riven (50 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org 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‑gaming.org
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!