3
\$\begingroup\$

I'm making a topdown 2.5D game (think the legend of zelda: a link to the past) using libgdx and box2D.

to simulate friction from a topdown perspective, i've set the gravity for the box2D world to 0, and added a friction joint to simulate friction with the floor.
this joint requires 2 bodies, one moving and one stationary and it slows down the moving one simulating friction.
my movable body is a dynamic body (player), and my stationary body (anchor) is a static body that is a sensor (to avoid collisions with bodies)

now I've increased the speed of the playable character, and it feels like he's skating over the ground.
I want to increase the friction, but after I'm not noticing any difference after changing variables.

the variables i've tried changing (that didn't seem to do anything) include:

  • the .friction on the fixtureDef of either body (player + anchor)
  • the size of the anchor
  • the .maxForce of the joint

How do I increase the friction caused by a friction joint in libgdx's box2D implementation?

\$\endgroup\$
1
  • \$\begingroup\$ Can you provide screenshot of your inspector or our code for better solution. \$\endgroup\$
    – Rakesh
    Commented Jun 22, 2017 at 16:19

1 Answer 1

1
\$\begingroup\$

After some further fiddling with the variables, increasing the maxForce on the FrictionJointDef did in fact increase the friction. it just needed a very large number (i'm using 55k) to get to a value that feels good.

\$\endgroup\$
5
  • \$\begingroup\$ If you need to set it to that high you really need to re-work your scale I'd imagine. Remember that you should be using meters for your units. \$\endgroup\$
    – Charanor
    Commented Jun 24, 2017 at 14:18
  • \$\begingroup\$ @Charanor that's what i'm worried about. i want my player character to move at a constant speed when pressing a key, so i'm using setLinearVelocity for it. The value that felt right was 50f. the player itself is a circle with a radius of 8f. i'll try to reduce the cirlce and the value for the linear velocity to somewhat lower values. \$\endgroup\$
    – Serris
    Commented Jun 25, 2017 at 20:29
  • \$\begingroup\$ That player has an 8m radius and moves at 50 m/s! The player radius should probably be around .5 or even .25 for a person-sized object (not sure how much space a human occupies haha...). And a human walks at about 1.5 m/s. Just in case you wanted some numbers ;) \$\endgroup\$
    – Charanor
    Commented Jun 25, 2017 at 20:33
  • \$\begingroup\$ Also it is suggested that you don't use setLinearVelocity and instead use applyLinearImpulse instead for constant speed. \$\endgroup\$
    – Charanor
    Commented Jun 25, 2017 at 20:40
  • \$\begingroup\$ @Charanor i had already looked into using linearimpulse, but it didn't achieve quite the same as the linearvelocity. i did put a little todo in my trello to follow up on it later. thanks for explaining the box2d measurements, it does sound a little silly when you put it like that :) \$\endgroup\$
    – Serris
    Commented Jun 26, 2017 at 13:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .