Best way to calculate the future?

Topics: Developer Forum, User Forum
Nov 25, 2010 at 1:13 PM

Hey, lets say that my entire world is static and also contains one circle, what would the best way be to simulate the circle for a 10 second path but fast enough to do it once per frame?

Should i just run 300 updates and store the values or is there anyway to do it that would be more efficent?

Nov 25, 2010 at 1:17 PM

Also if the circle stops moving collision events stop for on collision stop firing even thou sleeping is disabled, is this normal? how can i make it so it will trigger the collision event regardless of movement speed?

Nov 25, 2010 at 5:59 PM

Is it for replay? In that case it is best to record all the positions and rotations and replay them later. If it is to see into the future, you give the engine a 10 second timestep - however, if you want collisions to work correctly, you need to step it a lot of times with smaller timesteps.

As for your second question: Contacts are persistent between frames and thus it will only fire the OnCollision event once per collision. In order for it to fire more times, you will have to remove the contact and let the engine recreate it. A rolling circle should only create a single contact that is cached between updates. (Are you by any chance using the latest source control changeset? it contains a bug that creates multiple contacts when using edgeshapes.)

Nov 26, 2010 at 12:34 AM

Yer i am using the lastest changeset, so that would explain it.

No its not for replay its for predicting where the ball will be 10 seconds later if the player didn't apply any more force.

Nov 26, 2010 at 9:26 PM

I dont know what exactly you are trying to achieve, but i am wondering if there are no other forces than the player's forces involved if it would make more sense
to just cast a ray and reflect it on obstacles (unless these are moving too).

As said depends a lot on what you are trying to do (i was thinking kind of like a pool game showing the predicted path of the ball)


Nov 27, 2010 at 12:37 PM

I think i'm going to just ask for 30 or so extra steps each frame for 10 or so frames and store the positions i'm interested in and a list of all collsions that happened during the time.

The only thing i have wondering now is what would be best for rewinding the simulation back to before i started these calculations? How can i duplicate the physics simulation at a certain point and then destroy it later etc... as i will have to look around 10 seconds into the games future every 15 seconds or so...

Also almost everything in my world is static but I thought the raycast would miss objects from glancing hits etc... as the ray would not have the width of the circle.

And yes a good way to think of what i want is like is a pool game where the balls paths get predicted...

Nov 27, 2010 at 1:17 PM

Well regarding missing hits, with a circle you could simply raycast two rays from the circles edges, parallel to its velocity vector for example. Unless non static things are involved that would be a lot less hassle than stepping forth and back in the simulation i think. I wouldnt really know tho admitably.


Nov 27, 2010 at 1:20 PM

On most of the levels there are a few (around 2-10) dynamic objects, another reason that i can't do that, however you are correct raycasts from each edge would probably work in that case, i never thought of that.

I really now have to figure out how to save a entire state of a physics system and then reset it back to how it was after predictions, but it has to be fast and generate no garbage... :(

Any ideas Genbox?

Nov 28, 2010 at 6:03 AM

Also I should menchin that performance is a major concern as it has to run on the phone.