Changing speed of physics body over time

Hello, I’m making a game where things fall from above and we have to catch them. things falling are physics body.I want to increase the speed of them lets say whenever the score is >100.

All of the physics body are multi elements body and I have created them using PhysicsEditor by codenweb.

This is the line I use to grab the data of physics objects stored in other file:

local physicsData = (require  "shapedefs").physicsData(1.0)

This is the line I use to make the slect an object and add physics body to it:

physics.addBody(object, "dynamic", physicsData:get("object\_"..objName ))

Later on I have this to call spawnObject() Function:

timer1 = timer.performWithDelay (math.random(400,800), spawnObject,0)

So basically I want to know how can I increase the velocity or speed of the falling objects?

Hi @amdriod95,

Are you using gravity, or do the objects fall at a constant speed?

If you’re using gravity, you could just gradually increase the Y value of the gravity for the entire world. Alternatively, you could increase the “.gravityScale” of each object independently as you spawn them.

If you’re not using gravity, but rather assigning a direct linear velocity, simply increase the Y velocity of the objects as you spawn them.

Brent

I’m new to this I’m not really sure what physics editor did. Here is a part of the code I created with the physics editor:

["object\_apple"] = {                                          {                     pe\_fixture\_id = "", density = 2, friction = 0.3, bounce = 0.2,                      filter = { categoryBits = 1, maskBits = 65535, groupIndex = 0 },                     shape = {   23.5, -9.5  ,  24.5, 6.5  ,  16.5, 23.5  ,  8.5, 26.5  ,  -2.5, 24.5  ,  -0.5, -10.5  ,  7.5, -13.5  ,  17.5, -15.5  }                     }                      ,                     {                     pe\_fixture\_id = "", density = 2, friction = 0.3, bounce = 0.2,                      filter = { categoryBits = 1, maskBits = 65535, groupIndex = 0 },                     shape = {   -24.5, 7.5  ,  -24.5, -9.5  ,  -15.5, -15.5  ,  -9.5, -17.5  ,  -0.5, -10.5  ,  -2.5, 24.5  ,  -13.5, 27.5  }                     }                      ,                     {                     pe\_fixture\_id = "", density = 2, friction = 0.3, bounce = 0.2,                      filter = { categoryBits = 1, maskBits = 65535, groupIndex = 0 },                     shape = {   -0.5, -10.5  ,  -9.5, -17.5  ,  -6.5, -17.5  ,  -2.5, -15.5  }                     }                                           }

This is how it looks, and can you please give me the line which I should be adding to change the speed? 

The only thing within PhysicsEditor which could affect speed is the “density” value, but you’re not changing that so it doesn’t really matter. Changing the speed must be done after you create the objects, based on the two options I mentioned before.

Take care,

Brent

So should I be changing the density when ever I spawn my object?

I wouldn’t do so… let the density be auto-managed, and simply use one of the options I mentioned instead.

Thanks, Got it working by using gravityScale

Hi @amdriod95,

Are you using gravity, or do the objects fall at a constant speed?

If you’re using gravity, you could just gradually increase the Y value of the gravity for the entire world. Alternatively, you could increase the “.gravityScale” of each object independently as you spawn them.

If you’re not using gravity, but rather assigning a direct linear velocity, simply increase the Y velocity of the objects as you spawn them.

Brent

I’m new to this I’m not really sure what physics editor did. Here is a part of the code I created with the physics editor:

["object\_apple"] = {                                          {                     pe\_fixture\_id = "", density = 2, friction = 0.3, bounce = 0.2,                      filter = { categoryBits = 1, maskBits = 65535, groupIndex = 0 },                     shape = {   23.5, -9.5  ,  24.5, 6.5  ,  16.5, 23.5  ,  8.5, 26.5  ,  -2.5, 24.5  ,  -0.5, -10.5  ,  7.5, -13.5  ,  17.5, -15.5  }                     }                      ,                     {                     pe\_fixture\_id = "", density = 2, friction = 0.3, bounce = 0.2,                      filter = { categoryBits = 1, maskBits = 65535, groupIndex = 0 },                     shape = {   -24.5, 7.5  ,  -24.5, -9.5  ,  -15.5, -15.5  ,  -9.5, -17.5  ,  -0.5, -10.5  ,  -2.5, 24.5  ,  -13.5, 27.5  }                     }                      ,                     {                     pe\_fixture\_id = "", density = 2, friction = 0.3, bounce = 0.2,                      filter = { categoryBits = 1, maskBits = 65535, groupIndex = 0 },                     shape = {   -0.5, -10.5  ,  -9.5, -17.5  ,  -6.5, -17.5  ,  -2.5, -15.5  }                     }                                           }

This is how it looks, and can you please give me the line which I should be adding to change the speed? 

The only thing within PhysicsEditor which could affect speed is the “density” value, but you’re not changing that so it doesn’t really matter. Changing the speed must be done after you create the objects, based on the two options I mentioned before.

Take care,

Brent

So should I be changing the density when ever I spawn my object?

I wouldn’t do so… let the density be auto-managed, and simply use one of the options I mentioned instead.

Thanks, Got it working by using gravityScale