How to know when collisions are done with the physics?

Hi,

I watched the video tutorial about Angry Birds In 30 Minutes and learned how to add blocks to the physics and then throw an object to knock them down. I can also determine when certain items collide which is good. But how can I tell when all blocks are done falling? For example, when you play Angry Birds, it shows all of the blocks falling and finish before you can take another turn.

Thanks,

Warren
[import]uid: 184193 topic_id: 34977 reply_id: 334977[/import]

The best way to do this is add all physics objects (at least all that you’re concerned with checking) into a table, then use a repeating timer of maybe 1 second. On each iteration of the timer, you loop through the table and check each object’s linear velocity (both horizontal and vertical). If any object exceeds a certain range, you know that it’s moving beyond the “allowable amount” and you then break from the loop. It’s important that you break from the loop then, because if one object is moving, there’s no point in checking any others until the next timer fire.

Determining the allowable range of stability must be done only with testing. You need to see which level is acceptable to you. Note that in a physics simulation, basically no object that started moving will ever come to a perfect 0,0 linear velocity (full rest), even if it appears so. Thus, you need to give a small range of maybe -4 to 4 in either direction, with values between that range considered at rest.

Brent [import]uid: 200026 topic_id: 34977 reply_id: 139128[/import]

The best way to do this is add all physics objects (at least all that you’re concerned with checking) into a table, then use a repeating timer of maybe 1 second. On each iteration of the timer, you loop through the table and check each object’s linear velocity (both horizontal and vertical). If any object exceeds a certain range, you know that it’s moving beyond the “allowable amount” and you then break from the loop. It’s important that you break from the loop then, because if one object is moving, there’s no point in checking any others until the next timer fire.

Determining the allowable range of stability must be done only with testing. You need to see which level is acceptable to you. Note that in a physics simulation, basically no object that started moving will ever come to a perfect 0,0 linear velocity (full rest), even if it appears so. Thus, you need to give a small range of maybe -4 to 4 in either direction, with values between that range considered at rest.

Brent [import]uid: 200026 topic_id: 34977 reply_id: 139128[/import]

Hi,

I am getting ready to use this method to determine when objects are finished moving. How do I create a table with objects and loop through them? Is there an example of this somewhere?

Thanks!

Warren
[import]uid: 184193 topic_id: 34977 reply_id: 145206[/import]

Adding them is easy enough:

local t = {}  
t[#t+1] = myObject  

And looping:

for i = 1, #t do  
 print( t[i] ) --object reference  
end  

And VERY importantly, when you want to clear out (empty) the table in a cleanup routine, you must loop backwards through the table! Otherwise, Lua will only get every other instance, leaving you with a half-full table and a pending memory clog.

for i = #t, 1, -1 do  
 t[i] = nil  
end  

Hope this helps,
Brent [import]uid: 200026 topic_id: 34977 reply_id: 145211[/import]

Hi,

I am getting ready to use this method to determine when objects are finished moving. How do I create a table with objects and loop through them? Is there an example of this somewhere?

Thanks!

Warren
[import]uid: 184193 topic_id: 34977 reply_id: 145206[/import]

Adding them is easy enough:

local t = {}  
t[#t+1] = myObject  

And looping:

for i = 1, #t do  
 print( t[i] ) --object reference  
end  

And VERY importantly, when you want to clear out (empty) the table in a cleanup routine, you must loop backwards through the table! Otherwise, Lua will only get every other instance, leaving you with a half-full table and a pending memory clog.

for i = #t, 1, -1 do  
 t[i] = nil  
end  

Hope this helps,
Brent [import]uid: 200026 topic_id: 34977 reply_id: 145211[/import]

Hi,

I am getting ready to use this method to determine when objects are finished moving. How do I create a table with objects and loop through them? Is there an example of this somewhere?

Thanks!

Warren
[import]uid: 184193 topic_id: 34977 reply_id: 145206[/import]

Adding them is easy enough:

local t = {}  
t[#t+1] = myObject  

And looping:

for i = 1, #t do  
 print( t[i] ) --object reference  
end  

And VERY importantly, when you want to clear out (empty) the table in a cleanup routine, you must loop backwards through the table! Otherwise, Lua will only get every other instance, leaving you with a half-full table and a pending memory clog.

for i = #t, 1, -1 do  
 t[i] = nil  
end  

Hope this helps,
Brent [import]uid: 200026 topic_id: 34977 reply_id: 145211[/import]

Hi,

I am getting ready to use this method to determine when objects are finished moving. How do I create a table with objects and loop through them? Is there an example of this somewhere?

Thanks!

Warren
[import]uid: 184193 topic_id: 34977 reply_id: 145206[/import]

Adding them is easy enough:

local t = {}  
t[#t+1] = myObject  

And looping:

for i = 1, #t do  
 print( t[i] ) --object reference  
end  

And VERY importantly, when you want to clear out (empty) the table in a cleanup routine, you must loop backwards through the table! Otherwise, Lua will only get every other instance, leaving you with a half-full table and a pending memory clog.

for i = #t, 1, -1 do  
 t[i] = nil  
end  

Hope this helps,
Brent [import]uid: 200026 topic_id: 34977 reply_id: 145211[/import]