0 votes

How do I prevent my player sticking to platforms?
demo

in Engine by (192 points)

If you have any questions regarding my question or want me to elaborate on something specific regarding my question please do, I'm pretty desperate, thank you in advance.

First of all: your character isn't sticking to the platform, it's pushed down by it! I find that reasonable... What is the behavior you would have expected instead?

Other than that it would definitely be easier to help you, if you provided information about the node-types and script used for both the player and the platform.

Thank you so much for the response.

First off, I was expecting for my character to just fall not being bothered by the platform due to its gravity just like in the real world.


For the platform, its node structure looks like this:

| Node2D [script]
  | StaticBody2D
  | StaticBody2D

and Node2D's script just makes the cross platforms rotate:

extends Node2D

func _physics_process(delta: float) -> void:
    rotate(delta)

For the player I used move_and_slide_with_snap in _physics_process for handling velocity movement and stuff. Sticking to the platform might be due to how Godot processes move_and_slide. Debugging while sticking to the platform, the velocity resets to Vector2(0, 0) when it is collided on the ceiling.

Right now I have a barely working work-around, except:

  • The player doesn't fall when touching the floor.
  • The player penetrates the ground when getting squashed.
  • Force doesn't exist for the player, when getting shoved down by and object it acts like it's nothing.

Here's the code for now:

var new_velocity = move_and_slide_with_snap(velocity, snap, FLOOR_NORMAL)
if !is_on_ceiling():
    velocity = new_velocity
else:
    if velocity.y < 0:
        velocity.y = 0
    position.y += velocity.y*delta

Work-Around Results

1 Answer

0 votes

Make it so that if your on the ceiling zero the y velocity. This is a mechanic that is in almost every platformer and game where you can jump

by (659 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.