Troubles with Kinematic character and moving platforms

syskranksyskrank Posts: 8Member

I'm making a platformer game and utilizing the KinematicBody2D as a base for my character controller.

The problem is that when character is on the moving platform, the whole thing jitters. 

I mean that when the platform is moving up, character makes micro-jumps or just having tiny moments of free flight. 
Same thing goes for the downward movement, but the gaps between the character and kinematic platform are much bigger.

Platform is moved by animation from the level scene ( as it is in the demos ).

I'm pretty much following the KinematicCharacter tutorial & demo but with a few changes.

Also, I'm using Area2D to create a "feet" of my character to precisely determine ( and count ) ground contacts and can't get rid of collisions between the character and it's Area2D.

The structure is:

My code for the character.

Console output:

I believe that the solution for removing the jitter may reside in somehow "attaching" the character to the moving platform, but the "floor_velocity" approach from the demos doesn't work quite well ( jitter persists ).


Tags :


  • syskranksyskrank Posts: 8Member
    I've found the cause and the solution.

    The platform/character "vibration" is caused by move() function, which can not translate the physical body through the other one. So the platform goes up, bumps into the character, stops there, character goes up, platform catches up and so on. 

    So, to remove this effect, we should follow these few steps:

    1) Move platforms with velocity, not with animation ( yeah, not so neat, but you could expand the idea by path following and LERP ); 

    2) Keep track of the platform inside the character script ( register/unregister platform the character contacted with ), so you could do something like this:

    var p_vel = platform.velocity

    3) Apply gravity to the character only when it is in the air ( do not apply gravity when character is on the ground OR on the platform )

    4) If character is on the platform - reset vertical velocity to zero ( this is important )

    5) After character's force was integrated and velocity with motion were updated - move character with the tracked platform. Simple like this:

    # move with platform
    if ( null != platform ):
        move ( platform.velocity * delta )
  • BinaryOrangeBinaryOrange Posts: 235Member
    Glad to see you got this worked out! This actually is helping me with a game as well, I had been wondering how to counter-act the jitter caused by being on a moving platform (I'm making an elevator/lift kind of system). Thanks for sharing your solution! :smile: 
Sign In or Register to comment.