How to Make Objects Fall Faster in a Physics Simulation
Posted
by
David Dimalanta
on Game Development
See other posts from Game Development
or by David Dimalanta
Published on 2012-11-26T08:14:29Z
Indexed on
2012/11/26
17:28 UTC
Read the original article
Hit count: 318
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?
© Game Development or respective owner