Moving KinematicBody2D position with Tween Interpolation make the character cross through the platform collisor

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By arthurZ

Hi, I was making some tests with tween interpolation property, but I found this weird behavior (gif below). I was wondering if there is a way to avoid the KinematicBody2D from entering the platform’s collisionShape2D in this situation.

  1. This is the line I was using: $MoveTween.interpolate_property (self, "position", position, position + Vector (30, -100), 5.0, Tween.TRANS_SINE, Tween.EASE_OUT, 0.032)

  2. I set all layers and masks correctly, so that KinematicBody2D starts the gif colliding with the floor.

  3. Tween has Playback_proccess_mode Physics checked (is this right?).


enter image description here

Maybe the tweening function isn’t playing nice with the collision detection? Is there a way to make it work within the physics functions of KinematicBody2D?

Ertain | 2019-11-06 00:52

It’s weird, it’s almost like it doesn’t have a CollisionShape2D when it’s in the middle of the tweening. Maybe it’s the old problem of animating the position using position vector instead of trying another way.

But which another way??

Just as a test, I seted the velocity.y = -1000000 in move_and_slide method, and the KinematicBody2D respected the CollisionShape2D of the platform.

Why people don’t wanna to create a relative position for the AnimationPlayer using the move_and_slide algorithm or something like that? It could make things so much easy to animate.

I’m still waiting some help with this. =(

arthurZ | 2019-11-06 02:00

I don’t know if the developers can do that. :-/

Ertain | 2019-11-06 06:31

:bust_in_silhouette: Reply From: Asheraryam

I use Tween all the time, but it does not work well with Kinematic Body since changing the position or velocity manually causes issues.

If you do not need move_and_slide and only want to use Tween for movement, you should use a Rigid Body with the mode set to “Kinematic”, that way you can manually set the position and velocity safely inside _integrate_forces.

I always use Rigid Body with _integrate_forces since it gives the most flexibility with coding custom, Kinematic Body is suited for specific cases only (when you want regular physics movement with move_and_slide only).