One frame lag between IK and physics

In BGE, the actuators update before the physics does. This means that IK (updating in the logic/actuator stage) executes before physics. As a result you get an apparent one frame lag between the two. Consider this blend:
IKLagTest-physics.blend (539 KB)

The ball (which is the target of the IK) has a slight motion relative to the top of the robot arm.

Does anyone have any workarounds for this?

In object tab > relationship extras on the ball there’s a couple of “hack” options, maybe they will give the results you’re looking for.
I’m not sure, I can never get good results from physics so I’ve pretty much given up on it. All my games use fake physics.

Recently I had some trouble with a plane parented to the camera which didn’t update properly so the hud that was using it for a collision check didn’t work properly if the camera moved In that case I parented the hud to the camera too and it seem to work out OK. I don’t think that’d work here though since then physics would not affect the ball.

Usually the work around would be to have 2 different balls, parent the visible ball to the arm and then set the other with rigid body physics invisible, will that be good?

@Smoking_mirror:
I haven’t found any of those that work in the game engine.
It doesn’t surprise me that you’re doing that - because RTS’s generally don’t work well with generalized physics

@quramarx:
I may have to end up doing this, however I would (obviously) rather not. The actual system already has separate graphics and physics mesh, but there are moving parts+constraints+things on the end, so it will be a pain to set up.

Note:
Adding armature.run() to the scene.pre_draw callback didn’t fix it either - probably the armature has updated but the objects associated with it have not (or something like that)

In that case could you compensate the lag with math? verlet or leap frog? I do that when I don’t want to use parent

my math sucks but the leap frog? “seems” to be working, atleast for me


def veLeap(obj_dict,pos_current):
    dt =  1 / bge.logic.getLogicTicRate()
    pos_old = obj_dict["pos_old"]
    dx = pos_current - pos_old
    d_acc = dx * dt
    avg_acc =  d_acc - obj_dict["acc_old"] 
    avg_vel = (obj_dict["vel_old"] + d_acc) * 0.5    
    obj_dict["vel_old"] = dx
    obj_dict["pos_old"] = pos_current

    return (pos_old + pos_current) * 0.5 + avg_vel + avg_acc