Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I used the collision physics (i.e. Box2d, Physics Body Editor) and implemented onto the java code. I'm trying to make the fall speed higher according to the examples:

  • It falls slower if light object (i.e. feather).
  • It falls faster depending on the object (i.e. pebble, rock, car).

I decided to double its falling speed for more excitement. I tried adding the mass but the speed of falling is constant instead of gaining more speed. check my code that something I put under input processor's touchUp() return method under same roof of the class that implements InputProcessor and Screen:

@Override
public boolean touchUp(int screenX, int screenY, int pointer, int button) 
{
    // TODO Touch Up Event

    if(is_Next_Fruit_Touched)
    {
        BodyEditorLoader Fruit_Loader = new BodyEditorLoader(Gdx.files.internal("Shape_Physics/Fruity Physics.json"));

        Fruit_BD.type = BodyType.DynamicBody;
        Fruit_BD.position.set(x, y);

        FixtureDef Fruit_FD = new FixtureDef(); // --> Allows you to make the object's physics.
        Fruit_FD.density = 1.0f;
        Fruit_FD.friction = 0.7f;
        Fruit_FD.restitution = 0.2f;

        MassData mass = new MassData();
        mass.mass = 5f;

        Fruit_Body[n] = world.createBody(Fruit_BD);
        Fruit_Body[n].setActive(true); // --> Let your dragon fall.
        Fruit_Body[n].setMassData(mass);
        Fruit_Body[n].setGravityScale(1.0f);

        System.out.println("Eggs... " + n);

        Fruit_Loader.attachFixture(Fruit_Body[n], Body, Fruit_FD, Fruit_IMG.getWidth());
        Fruit_Origin = Fruit_Loader.getOrigin(Body, Fruit_IMG.getWidth()).cpy();

        is_Next_Fruit_Touched = false;
        up = y;
        Gdx.app.log("Initial Y-coordinate", "Y at " + up);

        //Once it's touched, the next fruit will set to drag.
        if(n < 50)
        {
            n++;

        }else{

            System.exit(0);

        }
    }

    return true;
}

And take note, at show() method , the view size from the camera is at 720x1280:

    camera_1 = new OrthographicCamera();
    camera_1.viewportHeight = 1280;
    camera_1.viewportWidth = 720;
    camera_1.position.set(camera_1.viewportWidth * 0.5f, camera_1.viewportHeight * 0.5f, 0f);
    camera_1.update();

I know it's a good idea to add weight to make the falling object falls faster once I released the finger from the touchUp() after I picked the object from the upper right of the screen but the speed remains either constant or slow. How can I solve this? Can you help?

share|improve this question
add comment

5 Answers

up vote 12 down vote accepted

It's basic physics: heavier objects don't fall faster!

A feather has a bigger area than a pebble; hence it gets slowed down by air resistance a lot more. Introduce a drag force that slows down objects the faster they fall, in the opposite direction of the velocity. The drag force will cancel out gravity once terminal velocity has been reached.

drag_force = object_specific_constant * velocity^2

The object specific constant is a combination of a lot of factors, including object size, fluid density and viscosity. The most important factor is size though! A feather is big with a lot of surface area; a pebble of the same mass is a lot smaller. The force gravity inflicts is the same (since they are the same mass) but the drag on the feather is a lot higher, so the feather slows down and reaches terminal velocity much sooner.

Pick a value that makes it behave like you want. I'd suggest something based on the object area (width * height * magic_value_that_makes_it_behave_like_I_want) for simplicity.

Box2d has something they call linear damping which works similar to this.

share|improve this answer
2  
I believe this is the most correct answer. Use different drag co-efficients for the different objects to achieve different fall rates. Most physics engines support this e.g Box2D. Although I suggest you revise your answer to include what Majd has stated that Mass does not typically affect fall speed. –  Stephen Tierney Nov 26 '12 at 10:36
    
Let's see what I can do for your answer. –  David Dimalanta Nov 26 '12 at 13:10
    
Although everything about this answer is correct, adding a drag force would be the incorrect way to handle the problem. Box2D already has built-in functionality for this. Not to mention, the equation you provide is pretty sketch. –  Amplify91 Nov 26 '12 at 17:01
    
@Amplify91 What's sketch about it? It's the actual formula for air resistance. –  Orin MacGregor Nov 26 '12 at 18:03
2  
I can see how it is confusing, I didn't even understand the name at first. It's just a constant that is specific to that object. In a real world scenario it would primarily be (and simplified to) the surface area being acted upon by the wind resistance. For programming it would just be an arbitrary number that would cause the object to behave as intended. Ccxvii should probably put this as an explanation in the answer. –  Orin MacGregor Nov 26 '12 at 20:46
show 2 more comments

Changing the mass will only have an effect on how the body's inertia (F=m*a), how it reacts to forces. Have you heard of Galileos experiment at the leaning tower of Pisa? If you want them to fall att different speeds you have to either:

  1. Set the velocity of the body after creation

    Body.setLinearVelocity(Vector2 v)

  2. Apply a force to the body after creation Body.

    Body.applyForce(Vector2 force, Vector2 point)

  3. Apply an impulse to the body after creation

    applyLinearImpulse(Vector2 impulse, Vector2 point)

share|improve this answer
1  
I agree with what you say about inertia, but this is not how it should be handled in Box2d. Firstly, if you want any kind of realism in your physics, NEVER manually set the velocity as you suggest in point 1. Applying vertical forces and impulses may get you closer to what you are trying to achieve (especially forces) but again, are the incorrect way of handling this and will not give the effect you are looking for. –  Amplify91 Nov 26 '12 at 17:04
1  
I can use Majd's idea for the next project later on. But for now, my current project, a stack-up game for the Android, needs to "cheat" the speed fall since this game tests the reflexes and puzzle solving skills. Best of all, kid friendly. –  David Dimalanta Nov 27 '12 at 1:38
add comment

As ccxvii said, heavier objects do not fall faster. The only reason lighter objects sometimes fall more slowly is because the have higher air resistance. In a vacuum, all objects fall at the same speed. LibGdx uses Box2D for physics and Box2D is pretty realistic so changing mass will not affect how fast an object falls. However, there are two ways around this to achieve what you are looking for:

  1. Simulate air resistance on your objects (more for lighter objects like feathers). Do this with the following code: yourBody.setLinearDamping(someFloatValue);
    Don't be afraid to set that value well above 1.

  2. Change the gravitation scale for each object. This is not a physically accurate option, but it may be just what you are looking for. In my platformer, I set my main character's gravitational scale to 1.4f so that he doesn't float as much while jumping and is easier to maneuver at high speed. Use this method: yourBody.setGravityScale(someFloatValue);
    Keep this value around 1 to avoid too much of the effect.

Set either of these values once when you are creating you objects.

share|improve this answer
    
Also, make sure your world's gravity is high enough to make your objects fall as fast as you want them to. Real world gravity is -9.8, but you may want to go higher. –  Amplify91 Nov 26 '12 at 17:07
1  
About number 1, setLinearDampling(), is it possible to set a negative number, over -9000, for even heavier? –  David Dimalanta Nov 27 '12 at 2:00
    
@DavidDimalanta Can't tell if troll... I've set it around 10 before. –  Amplify91 Nov 27 '12 at 2:12
    
Have you played Jewel Stacker for the Android? Two the same square gems and I tried this game. I drag the first square gem at the top and the second one on the center. Then, I run on both at tremendous speed but the first one falls faster than the second one; even if I set the first one on top and the second on the middle, the first square catches up the second while falling like a race. This is the concept I was trying to look for for defying gravity. It maybe possible at @Majd's answer, so were you, but on the gravity concept. –  David Dimalanta Nov 27 '12 at 2:17
add comment

Seems like your Box2d world is using 1 px = 1 meter. Imagine that you are playing with huge objects with tons weight in real world - that is what happening in your game. Make it ~50 (+/-20) px = 1 meter and play with it.

Wish you luck.

share|improve this answer
1  
Where can I find it to adjust the pixels per meter thing? –  David Dimalanta Nov 27 '12 at 7:37
    
When you creating new box2d object you just need to devide all the parameters by your devider, for example 30. I mean the following: –  Mikle Pankratov Nov 28 '12 at 6:18
1  
No. You can play with bodys mass, density, gravity, but what I said is the most common bug. –  Mikle Pankratov Nov 28 '12 at 11:31
1  
yeap, he is right. quote: "you should convert the values received from Box2D from meters to pixels. This will improve the stability of the physics simulation." link: box2d.org/2011/12/pixels –  Mikle Pankratov Nov 28 '12 at 13:16
1  
=) good luck!!! –  Mikle Pankratov Dec 3 '12 at 10:48
show 7 more comments

Just increase the gravity acceleration, there is a basic formula:

V = 0.5 * g * t^2

g -> gravity acceleration t -> time in the air

share|improve this answer
3  
I don't think this adequately answers the question, considering there is another already established and accepted answer. –  ktodisco Oct 16 '13 at 16:23
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.