how can I make my player stick/not glitch out to a vertically moving platforms?

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

So I made a moving platforms that’s made directly on the world, by creating a KinematicBody2D and setting its animation using animation player with a position track, I was able to create a moving platform. The horizontally moving platforms worked really well, but the vertical one didn’t. On KinematicBody2D, the platform would glitch out the player that makes the players sprite somehow lower when going up making the feet inside the platform. I changed the Kinematic to a StaticBody2D but the problem is, when the platform is going down, my character would fall, rather than just sticking to the platform. Is there anyway I could solve this?, or do I have to manually code it?

:bust_in_silhouette: Reply From: Darkcloud

Did you enable “Sync To Physics” for the KinematicBody2D (platform) in the inspector?

It worked! ty so much

GrandeHolt | 2023-01-08 05:16

:bust_in_silhouette: Reply From: fattusrattus

i’m gonna go out on a whim and hope this helps because this is just my initial thought reading this:

Use an Area2D around the platform(s) you want to cling to, and use the space override to create a new gravity point for your character. Then make a signal for said Area2D node when you enter it to change the gravity point of your character. To make it a universal thing, you could also put the platforms into a group (i’d call it “MovingPlatforms” just for the sake of convenience), and make the signal call change the player’s gravity origin for the group, rather than having to do it for each platform individually.

I hope that helps somewhat (;・∀ ・)

I didn’t want to complicate it too much its working now but ty for your answer :3

GrandeHolt | 2023-01-08 05:17