I faced with some problems in implementation of manual kinematic movement with using fixed_update()
and fixed_update_frequency
.
To move the kinematic body I set go position in fixed_update()
, then get the contact_point_response
messages and correct the position according the collisions. Then in the update()
function I interpolate the position between the previous one and the new one according the time.
function fixed_update(self, dt)
self.last_fixed_update_time = os.clock()
self.last_fixed_update_dt = dt
self.initial_position = self.position
-- Next code changes self.position according the movement.
-- ...
end
function update(self, dt)
local current_update_time = os.clock()
local interpolation = (current_update_time - self.last_fixed_update_time) / self.last_fixed_update_dt
interpolation = math.max(0, math.min(1, interpolation))
local lerp_position = vmath.lerp(interpolation, self.initial_position, self.position);
go.set_position(lerp_position)
end
where:
-
self.initial_position
— an old position before moving, taken from beginning offixed_update()
. -
self.position
— a new calculated position after runningfixed_update()
and handling thecontact_point_response
messages.
The result with fixed_update_frequency = 10
to hyperbolize visual problems:
In the video you can see that every 1/10th of a second fixed_update() is called and the future position is set to check for collisions. And immediately a rendering takes place. Then in the next frames an update() is executed, where the correct interpolated position is set.
So, the question
- Is it okay that after a position change in
fixed_update()
the rendering happens? Or this is a bug and rendering should only happen afterupdate()
? - If this is okay, is the solution to move the kinematic collision object separately from the capsule model? I.e., move the model+camera only in the
update()
loop and move the collision object only infixed_update()
to avoid this invalid frame? Sounds logical, but it breaks the integrity of the object. - Any other ideas how to solve it?
More context: