I’m working on a 2D platforming game and im trying things out with falling blocks, but weird things are happening when the block falls while the player is standing on it. Basically the player will follow the velocity of the block and is_on_floor() will return true while falling, despite having a small gap between them and the block? I’m very confused and was wondering if anyone knew what property could be causing such a thing and how I could prevent it from happening?
Here is what it looks like, and both the player and the falling block are CharacterBody2D :
I tried every combination of PlatformOnLeave property on both the player and the falling block, and tried tweaking the snap length on both the player and the falling block, but nothing changed
That was my initial plan, but AnimatableBody2D dont have a velocity property which makes it really hard to make it fall and collide with the ground, which is why I was using a CharacterBody2D instead and tried to figure out how snaping worked with it
is_on_floor()'s underlying value is set when you call move_and_slide(). Unfortunately, neither of these methods are easy to fiddle with in GDScript so there’s not much you can do. There’s more information on how CharacterBody2D works here:
One thing that might work is switching the platform’s collision layer when it starts to drop to one that isn’t enabled in the CharacterBody2D’s platform_floor_layers:
I haven’t tried this though.
@KatDawg57’s suggestion of using a RigidBody2D is a good one if you just need it to drop once it’s triggered. Simply freeze it by default, and then unfreeze it when the character lands on it. You could give it a little extra kick by applying a downward impulse after you unfreeze it if you want it to accellerate more quickly.
The AnimatableBody2D suggestion is even better if you want platforms which behave predictably and won’t be pushed around by other physics entities (and don’t mind that they won’t bounce around when they land and do other physicsy things). You could add your own velocity to it by animating it in code. For example:
extends AnimatableBody3D
var velocity := Vector3.ZERO;
var activated := false;
func _physics_process(delta: float) -> void:
if (activated):
velocity = velocity + get_gravity() * delta;
if (move_and_collide(velocity * delta)):
velocity = Vector3.ZERO;
You could do something like that, setting activated to true when the player collides with the platform. Since you can program the movement however you want this way, you have a lot of control over how it moves.