Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (774)
Games in Android Showcase (230)
games submitted by our members
Games in WIP (856)
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] What method of capping angular velocity/force  (Read 3966 times)
0 Members and 1 Guest are viewing this topic.
Offline Gibbo3771

JGO Kernel


Medals: 128
Projects: 5
Exp: 1 year


Currently inactive on forums :(


« Posted 2014-05-13 08:58:54 »

I am in the process of creating a basic Asteriods clone and wondering what is the best way to cap forces on the body.

Say I want to cap the ship speed to 1m/s, should I do a simple if statement to achieve this? I notice there is a way to set dampening but this gives less control but a nicer "feel" if that makes sense.

What way should I do it?

"This code works flawlessly first time and exactly how I wanted it"
Said no programmer ever
Offline atombrot
« Reply #1 - Posted 2014-05-13 09:13:11 »

I do the following to cap my max speed:

1  
2  
3  
4  
5  
Vector2 velocity = body.getLinearVelocity();
float speed = velocity.len();
if (speed > MAX_SPEED) {
    body.setLinearVelocity(velocity.scl(MAX_SPEED / speed));
}


Edit: Ah sorry, just have seen that you asked for angular velocity in the thread title. The angular velocity defines how fast an object rotates. Not sure if this is really what you want, but if so, you can do basically the same thing, as for the linear velocity. The check needs to take into account, that the velocity can also be negative, but other than that it's the same logic.
Offline Gibbo3771

JGO Kernel


Medals: 128
Projects: 5
Exp: 1 year


Currently inactive on forums :(


« Reply #2 - Posted 2014-05-13 09:33:19 »

I would want to cap both so your answer applies just fine Cheesy

So using the dampening is a bad idea?

"This code works flawlessly first time and exactly how I wanted it"
Said no programmer ever
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline atombrot
« Reply #3 - Posted 2014-05-13 10:58:16 »

I use the method described above to cap the speed. As I understand the damping is a way to slow bodies (or their rotation) over time. You can check out my LD29 game ( http://www.ludumdare.com/compo/ludum-dare-29/?action=preview&uid=7738 ). I used a very low damping value, so the cells in the game continue to drift in the same direction, even if the player stops pressing the direction keys. It creates quite a floaty feel to the game.

I'm getting to know box2d a bit better by building a pong game. There I also linear use damping, but for the paddles. The damping value is quite high. With this the player can release the direction keys and the paddle will still slide a bit further in the direction instead of stopping instantly.

So I think the damping is a very valuable tool in box2d. You have to try out what parameters work best (keep in mind that the strength of the damping might also be related to the mass. more mass => damping has less effect. I'm not sure about this but it would make sense).

But I don't use the damping to limit the speed. I think it is the wrong tool for that.

Please take my advice with a grain of salt, because I just started using box2d some weeks ago.

And if you want to stop your bodies from rotating, then you can use body.setFixedRotation
Pages: [1]
  ignore  |  Print  
 
 

 
EgonOlsen (1865 views)
2018-06-10 19:43:48

EgonOlsen (1887 views)
2018-06-10 19:43:44

EgonOlsen (1256 views)
2018-06-10 19:43:20

DesertCoockie (1688 views)
2018-05-13 18:23:11

nelsongames (1357 views)
2018-04-24 18:15:36

nelsongames (1975 views)
2018-04-24 18:14:32

ivj94 (2743 views)
2018-03-24 14:47:39

ivj94 (1945 views)
2018-03-24 14:46:31

ivj94 (3036 views)
2018-03-24 14:43:53

Solater (1088 views)
2018-03-17 05:04:08
Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45

Deployment and Packaging
by philfrei
2018-08-20 02:33:38

Deployment and Packaging
by philfrei
2018-08-20 02:29:55

Deployment and Packaging
by philfrei
2018-08-19 23:56:20

Deployment and Packaging
by philfrei
2018-08-19 23:54:46
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!