Any suggestions for how one could simulate the physics for a few ‘ticks’ within one app frame, look at all the intermediate values and then rewind before updating to the next frame. Essentially I want to be able to look into the future a little before taking the next step. [import]uid: 199243 topic_id: 34696 reply_id: 334696[/import]
In the very short term you can use the getLinearVelocity to see where objects are likely to be, however this will not take into account gravity - you’d have to work that out yourself. That’s not too hard, if you search the net for some basic gravitational maths. [import]uid: 8271 topic_id: 34696 reply_id: 137901[/import]
Thanks Horacebury but I need it to take into account collisions etc, so that wouldn’t work. [import]uid: 199243 topic_id: 34696 reply_id: 138048[/import]
Method 1 - ugly:
Use an invisible sensor object. Have an enterFrame listener (called for every frame rendered) or timer and in each tick of the listener estimate where the visible object will be and put the sensor there. The sensor object will have a collision listener on it to tell you if it will collide with something. Your visible object can be altered accordingly.
Method 2 - pretty:
As detailed in today’s blog post, you could add a sensor shape to your physics body which is a bit larger than your visible physics body. This can then be used to detect a “future” collision because the larger sensor would collide with objects earlier than the main body. This could also be done with lots of smaller sensor bodies placed around the edges of your visible body. This avoids having to “predict” where Box2D is going to send your physics body along its trajectory.
Blog post: http://www.coronalabs.com/blog/2013/01/08/working-with-multi-element-physics-bodies/
My preference is Method 2. [import]uid: 8271 topic_id: 34696 reply_id: 138057[/import]
In the very short term you can use the getLinearVelocity to see where objects are likely to be, however this will not take into account gravity - you’d have to work that out yourself. That’s not too hard, if you search the net for some basic gravitational maths. [import]uid: 8271 topic_id: 34696 reply_id: 137901[/import]
Thanks Horacebury but I need it to take into account collisions etc, so that wouldn’t work. [import]uid: 199243 topic_id: 34696 reply_id: 138048[/import]
Method 1 - ugly:
Use an invisible sensor object. Have an enterFrame listener (called for every frame rendered) or timer and in each tick of the listener estimate where the visible object will be and put the sensor there. The sensor object will have a collision listener on it to tell you if it will collide with something. Your visible object can be altered accordingly.
Method 2 - pretty:
As detailed in today’s blog post, you could add a sensor shape to your physics body which is a bit larger than your visible physics body. This can then be used to detect a “future” collision because the larger sensor would collide with objects earlier than the main body. This could also be done with lots of smaller sensor bodies placed around the edges of your visible body. This avoids having to “predict” where Box2D is going to send your physics body along its trajectory.
Blog post: http://www.coronalabs.com/blog/2013/01/08/working-with-multi-element-physics-bodies/
My preference is Method 2. [import]uid: 8271 topic_id: 34696 reply_id: 138057[/import]
I now think what I’m looking to do isn’t possible within the Corona framework. What I need to be able to do is tick the full Box2D simulator for a second say, so that it calculates the outcome, rather than my estimating it, as you have suggested. It would require decoupling Box2D from the rest of the scene update framework. Thanks for your suggestions though. [import]uid: 199243 topic_id: 34696 reply_id: 139924[/import]
I now think what I’m looking to do isn’t possible within the Corona framework. What I need to be able to do is tick the full Box2D simulator for a second say, so that it calculates the outcome, rather than my estimating it, as you have suggested. It would require decoupling Box2D from the rest of the scene update framework. Thanks for your suggestions though. [import]uid: 199243 topic_id: 34696 reply_id: 139924[/import]