srikarg

Drag Sprite Body In Air

Recommended Posts

Hello everyone,

 

Is there any way to adjust the drag of a sprite in the air (I know you can do it on the ground)? Right now, when the character in my game jumps into the air off of the ground, it can move horizontally very easily. In other words, the horizontal movement sensitivity is extremely high. Is there any way to reduce this sensitivity and add some sort of drag to the sprite's body when it is in NO contact with any obstacles (i.e. no collisions)?

 

Thanks in advance,

srig99

Share this post


Link to post
Share on other sites

The body.drag value reduces the velocity, whether it's in the air or not - it simply reduces the velocity constantly so that the velocity sooner or later returns to 0.

 

You could either disable the ability to change velocity entirely when the character is in the air (remove air control) or you could increase the body.drag.x value when the character is in the air by an amount that feels natural while giving a bit of air control. I guess you could also set the body.maxVelocity.x value to something lower when the character is in the air.

Share this post


Link to post
Share on other sites

you can also do the following and set drag to zero, to manually simulate drag when the character is touching down. You can negate the if, or use an else to have separate friction for the air and surfaces, or do a more complex checking if there are different type of surfaces with different friction like ice, grass, air with or without changing wind :)

if (player.body.touching.down) {
    player.body.velocity.x = player.body.velocity.x / 1.1;
}

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.