# Trouble understanding friction and drag

## Recommended Posts

I'm using physics in one of my games, but I'm having trouble getting things to move realistically. I have the player (a bird), and I have objects in a group (trash). The trash I want to be very lightweight, so that it can be knocked around by the bird. Setting mass on both the player and the objects sometimes results in some weird visual stuff, so for now I have taken those lines out. What I really want to solve is the issue of friction.

Right now, my code looks like this:

``````  this.trash.forEach(function (piece) {
piece.anchor.setTo(0.5, 1);
piece.body.gravity.y = 5;
piece.body.moves = true;
piece.body.velocity.setTo(100, 100);

piece.body.collideWorldBounds = true;
piece.body.bounce.set(0.8);
piece.body.friction.x = 1;
piece.body.drag.x = 1;
});``````

The trash is gliding around on the floor of the game like wet ice cubes. I thought perhaps introducing another sprite to interact with would help:

``````this.platforms = this.add.physicsGroup();

// Create the ground and set properties.
this.platforms.create(0, game.height - 5, 'ground');
this.platforms.setAll('body.allowGravity', false);
this.platforms.setAll('body.immovable', true);
this.platforms.setAll('body.moves', false);
this.platforms.setAll('body.velocity.x', 100);
this.platforms.setAll('body.friction.x', 1);
this.platforms.setAll('body.drag.x', 1);``````

I'm still watching ice-cube trash.

What I'm aiming for is something that can tumble (is there a way to get corresponding rotation on collision to happen?), so I want moving the trash to be more of a shove to move a distance rather than a tap from the player.

##### Share on other sites

In Arcade Physics friction is how much of one object's movement (0–100%) is transmitted to a second object that's riding it. Drag is acceleration (px/s²) against an object's velocity.

Try increasing drag.x to 100 or so.

##### Share on other sites

I no longer have ice cubes for trash. Thank you, samme! The sweet spot is somewhere between 100 and 500 it would seem.

Is there a way to get sprites to "roll"? I see that you can do rotation, but I would imagine that if rolling occurs using rotation, it'd be related to a function/some math.

Again, thanks.

EDIT 7:35 pm EST -- Should I look into angular velocity?

##### Share on other sites

I often do a fake roll with

``sprite.body.angularVelocity = K * (sprite.body.velocity.x + sprite.body.velocity.y);``

where K is some number.

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.