When i apply this force to the player body.applyForceToCenter(new Vector2(dir.x*500000*999999, dir.y*500000*999999), true);
I get practically the same effect as when I do this body.applyForceToCenter(new Vector2(dir.x, dir.y), true);
. this line of code is in a method that is called when the player is supposed to move in a particular direction dir
which is a Vector2
. I've tried calling the method multiple times and using applyForce()
,applyLinearImpulse()
.
Asked
Active
Viewed 105 times
1

DreamsInHD
- 403
- 5
- 17
-
What are the values of dir.x and dir.y? how big/dense is your body or what mass is it? if its very small and very light then you are probably hitting the speed limit of box2D which is about 120m/s – dfour Jun 28 '17 at 16:24
-
1Just and FYI but box2d doesn't like very large or very small objects due to precision. The best ranges IMO are between 0.05 and 30 units. – dfour Jun 28 '17 at 16:26
-
the x and y is the delta calculated from touchDragged. The delta of the last touch and the new touch. The object is 50x50 and density is 0.0001f – DreamsInHD Jun 28 '17 at 17:57
-
Adding to @dfour, [there is a maximum velocity](https://stackoverflow.com/questions/14774202/is-there-an-upper-limit-on-velocity-when-using-box2d). Once you reach 120 m/s, you won't see any difference. – Salem Jun 28 '17 at 20:19
1 Answers
1
Box2D does have a velocity cap, which is 2 units per time step. Assuming 60 FPS, this would mean the maximum velocity is 120 m/s.
If we assume dir
is normalized you will eventually reach an acceleration of 500000*999999=499999500000
m/s^2 - which is somewhat large and reaches the limit very quickly.
This means that in one second the velocity will have increased by 499999500000 m/s, which is far above 120.
As @dfour said, use smaller objects and values - Box2D works optimally when objects are between 0.1 and 10 m in size.

Salem
- 13,516
- 4
- 51
- 70
-
thank you, but how do I show the square at the same size on screen as it is now? I'm using a `ScreenViewport`, my understanding of viewports is very limited but I read that with this viewport 1 unit == 1 pixel. If I resize do I, everytime I'm drawing something on screen, have to convert pixels to world units, and does that include the scene2d stuff? Also what would you recommend to resize it to? – DreamsInHD Jun 29 '17 at 06:25
-
1In general when using ScreenViewport and box2D you would use some sort of ratio between the screen pixels and box2D units due to the nature of screen sizes. Some good values are 8, 16, 32 and 64 pixels per unit. This means when you set your screen size in the Orthographic camera you would divide the width and height by your chosen pixel per meter ratio. e.g a 1024x768 screen using a 16 pixel per unit ratio would be 64 x 48 – dfour Jun 29 '17 at 09:28
-