How to make a 'marker' in a game

Hey guys, this isnt a how to thread first of all. I’ve created a marker ability in my spline rider game, so what it does is saves the position,angle,angularVelocity,linearVelocity in a table and then restores them next time the simulation is run, but this creates a simulation that’s slightly different and when the marker is removed the simulation will not always work all the way through because the splines have been set in position for the simulation from the marker, not from the start. Has anyone come across this problem before and found a solution? Thanks!

@Luatee do you mean that you are reconstructing your splines from the saved positions (“marker”)?

Deleted:understood you wrong.

Sounds like you start conditions with Box2d issue again I guess…

@Simeon its not that, I save and load the splines vertices and create them, that works fine. The problem is the bike, I save the position and such of the bike and then when I run the simulation I set those attributes of the physics body back to those previously stored values of the position and velocity etc, but when I do this it runs differently from that point onwards compared to the normal simulation without a marker

@Saurabh you might have a point with the use of tables, I could see this maybe changing the values but as long as all values are stored in one frame and none of them differ then it should be alright? I cant test this now as im not near my ipad but ill be sure to check it out when I get back

I dont get quite what you mean?

Your other thread where you got different outcomes every second run. By saving the physics object state part way, and then replaying it from there you have a different set of start conditions for Box2d and maybe that’s the cause of the change in behaviour.

@Luatee why not always set the bike from the marker whenever you initialise it? That is, every time you position the bike, create a marker for it and then reload the position from the marker.

@spacemonkey this wouldn’t happen as I have made it stop alternating between different states, it only ever follows one and this is what is causing my confusion.

@simeon im not quite sure you understand what im saying, or maybe im just not getting what youre saying but ill get a video demonstration up showing what I mean im heading back now anyway so there’ll be one with you shortly

@Luatee my understanding of your problem is that you have two code paths that produce two different simulations:

  • Initialising the bike on startup with some position (or when the user newly positions the bike?)
  • Initialising the bike from a saved state when a user reloads the level

Is this correct? My suggestion was to save and load the physics state in the first scenario as well.

http://youtu.be/2ENKYzWhPf0 there’s the demonstration. Basically, the circle with the line coming from the centre is the marker, the line shows a vector and the magnitude of it. You’ll see the two different runs from when I start each one.

@Simeon I have sorted the problem of the two paths and now the bike will only ever follow one.
The bike only has a saved state while in game if a marker is set it never gets saved to any local data or anything, this means if the bike is following one path all the time but just so happens to start half way through the simulation instead (from a marker) it changes course, but it shouldn’t from my understanding if box2d is deterministic?

@Luatee I see, so you’re starting the simulation with the same properties for the body, but at a different point in time. Box2D is deterministic, but it will likely not generate the same path because the sequence leading up to that point has changed.

@Simeon so what you’re saying is its probably not fixable? Or should an effort be made to tackle the problem?

You would probably need to “warm start” the simulation — that is, run it to the point of the marker, and then start play back — in order to get identical results. That’s a bit hard in Codea as the simulation is bound to the run loop for convenience.

You could also record the simulation rather than re-simulate. @John might have some ideas

@Simeon So you’re saying run the simulation until the bike reaches the marker point and then set the simulation to be shown so its is just like fast forwarding to the point of the marker then playing normally?

I thought about the recording of points to make a more accurate run when I began the project itself but then I disliked the idea of changing previous splines as it would make this more difficult if you know what I mean, I’d have to check for changes then re record and so on