Freeze character to camera

Long time since!

I got an idea for a function that I would love to try out but I’m not able to do this without a simple script. It goes as following:
-Players mesh get’s the position of the player every time it hit’s a new keyframe in it’s action.
-Then it’s parented to the camera.

It could maybe work with having the player parented to the camera all the time, but for every new camera frame it would re-position itself to the player object.

If it’s hard to understand the two main questions it:
What’s the script to orient an object to another? (Copy orientation)
Is it possible to make a script run every time a keyframe in an animation action is hit? How?

obj.worldOrientation = obj2.worldOrientation.copy()

log the action actuator to a property, then check that property with property brick or python, if changed do stuff

Thanks for taking your time.

The orientation worked fine, I’m still having an issue with the keyframe updater. It updates the whole time when the action is active rather than on every keyframe. Have in mind that the animation just occurs every 2nd or 3rd frame (imaging stop-motion). Is there a way to only run the script when a new keyframe is introduced/hit?

def something(cont)

    own = cont.owner
    armature = own.scene.objects['armature']
    layer = 0 #the layer where the animation is playing on
    if armature.isPlaying(layer):
        frame = armature.getActionFrame(layer)
        if frame > 2 and frame < 4:
            # do something on frame 3
        elif frame > 4 and frame < 6:
            # do something on frame 5

Btw, Do not use something like: if frame == 3: because that will not always work/getting executed.

#edit 2
Also you can just play the frame you like from your animation thus skipping a few frames, to do that:

start = 3
end = 3
armature.playAction('the animation to play', start, end, layer = 0, mode = 0)

this will play (mode 0 is play 1 is loop) frame 3 of the animation nothing else