Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Mike Trevor |
How do I prevent my player sticking to platforms?
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.
Mike Trevor | 2020-04-01 09:24
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.
njamster | 2020-04-01 11:08
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
Mike Trevor | 2020-04-01 13:06