• 2D
  • Troubles with Kinematic character and moving platforms

Hello.<br><br>

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

<br>

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

<br>

I mean that when the platform is moving up, character makes micro-jumps or just having tiny moments of free flight.&nbsp;

Same thing goes for the downward movement, but the gaps between the character and kinematic platform are much bigger.

<br>

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

<br>

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

<br>

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.

<br>

The structure is:<br><br> <img alt="" src="https://s4.postimg.org/i3o7w5xdp/char_struct_screenshot.png" title="Image: https://s4.postimg.org/i3o7w5xdp/char_struct_screenshot.png"><br><br>My code for the character.<br><br>

<p>Console output:</p><p><img src="https://s4.postimg.org/fnszu8899/char_collision_output.png" alt=""><br></p><p>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 ).</p>

I've found the cause and the solution. <br><br>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.&nbsp;<br><br>So, to remove this effect, we should follow these few steps:<br><br>1) Move platforms with velocity, not with animation ( yeah, not so neat, but you could expand the idea by path following and LERP );&nbsp;<br><br>2) Keep track of the platform inside the character script ( register/unregister platform the character contacted with ), so you could do something like this:<br><br>var p_vel = platform.velocity<br><br>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 )<br><br>

4) If character is on the platform - reset vertical velocity to zero ( this is important )<br><br>5) After character's force was integrated and velocity with motion were updated - move character with the tracked platform. Simple like this:<br><br>

# move with platform

if ( null != platform ):

&nbsp; &nbsp; move ( platform.velocity * delta )<br>

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:&nbsp;<br>