I’m trying to improve RenderCam, but there doesn’t seem to be any decent way to get an up-to-date object transform for rendering – i.e. a transform that’s not one frame behind.
It’s the same problem as in this thread: Dealing with the one frame lag when visualising dynamic bodies
The root of the problem is:
A) There’s no script callback after physics update but before render update
B) The render script doesn’t have access to ‘go.’ functions.
From what I can tell, the relevant part of the engine’s update loop goes like this:
- script update
- script on_message (get message sent to self on update)
- physics update (get physics messages in on_message)
- render script can get message from active camera component
- render script update
Object transforms are updated between each of the first 4 steps.
-
Anytime you move the camera, its world transform becomes out of date until the next point in the engine’s update cycle.
-
So, if your camera is attached to a physics object, or if you move it during any physics message response, you have no way of getting it’s updated transform.
-
The built-in camera component does work—it messages its View and Projection matrices to the render script after the physics update—the problem is, only one active camera does this, and I want to support multiple cameras at once (for split-screen, minimaps, rear-view mirrors, etc.).
Currently my camera sends a message to itself in update(), and updates its position and stuff when it gets that message (making its world transform out-of-date). I haven’t tested the exact reasons for that in a while, but I recall it jittered like crazy if I didn’t do it. The only thing after that to hook into is physics messages. So the only current solution I can see, is to do a physics raycast every frame and get the transform in the “ray_cast_missed” message response. That’s a bit more “hacky” than I’m willing to be at the moment.
Possible solutions
The easiest fix I can see is to allow render scripts to get info about objects. In my specific case, if the render script could do go.get_world_transform()
, then I think my problem would be solved. (Of course access to other getters would be good.)
The other way is to add another “post_update” script callback, called after physics are updated but before rendering.