Rotating platform's collision is behind

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

First of all: I am quite new to godot and programming in general, so please excuse me if I make any dumb mistakes!

I am making a platformer. I tried making a platform which rotates around a certain point. I made it rotate using an AnimationPlayer, which rotates the platform’s parent one way and the platform itself the other way. (there’s some space between the parent and the platform)
The Platform is just a KinematicBody2D with a Sprite and a CollisionShape2D

The problem is that the collision of the platform seems to be a few pixels behind. This causes the player to look like they’re in the air when the platform is going down, and when the platform goes up it looks like they’re inside of the platform.

I wouldn’t be surprised if the AnimationPlayer is at fault here. I did set the Process Mode to ‘Physics’, but maybe this is just a bad way of doing this?

:bust_in_silhouette: Reply From: Merlin1846

I don’t know if this would work, (I don’t have much experience with the animation player) believe the tween would work, but you would have to take your animation and turn into code.

extends Node2D

func _ready():
  ##Change $Tween to the path to your tween node. You'll only need one in the
  ##entire scene, though you can have more if you want.
  #Tell the tween to play during the physics process
  $Tween.playback_process_mode = Tween.TWEEN_PROCESS_PHYSICS

    #Make it loop when it finishs
$Tween.repeat = true

#Change the 2nd to last peramiter to change how long it takes to turn 360 degrees.
#Change the last peramiter to change the function used to interpolate. You
#probably won't need to change it but it could be cool to see what the other
#ones do.
#Change $Sprite to the path to the platform.

#Tells the tween to start the animation defined earlier.

Also sorry about the code being in spaces but that’s just the way Godot Q&A does things.

It rotates the platform but the problem remains.

Kekd | 2021-02-24 13:49

I don’t know what the problem is, but can you tell me the frame rate your game is running at, and also if you have low processor mode turned on for your game?

Merlin1846 | 2021-02-24 15:42

Low processor mode is turned off. Game fps is consistently 60.

Kekd | 2021-02-24 18:21

What kind of physics body is the player, and can you tell me how fast the platform is spinning in degrees? Because if the platform is spinning to fast it might be lagging through the players hit box. Another thing to try might be to try increasing and decreasing the players hit box size by 1 or 2 pixels.

Also I found this video by game endevour who is actually currently working on Godot’s development.

Merlin1846 | 2021-02-24 23:54

The player and the platform are both KinematicBody2D, though the same problem happens when I put a RigidBody2D on the platform.
The platforms are all moving very slowly. Changing the player’s hitbox doesn’t improve it.
After a little bit more testing I found out that this happens with any kind of moving platform, even if it’s only done with code. I might just make a new question as this seems to happen with any kind of movement, not just when rotating something.

Kekd | 2021-02-25 13:37

Actually, I just solved it, lol.
I didn’t turn sync to physics on on the Platform. The reason I didn’t is because at first sync to physics (for some reason) caused the platform to not move at all, so I just assumed it didn’t help. Now it somehow solves everything.

Kekd | 2021-02-25 13:41