RigidBody2D sinking into StaticBody2D ground

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Sigma-One
:warning: Old Version Published before Godot 3 was released.

I have an infinite runner game set up, the idea is that you can flip gravity. But if I set my gravity variable to anything higher than 50, the player object sinks into the ground. The player is a RigidBody2D in character mode (because I couldn’t figure out collisions for a KinematicBody2D), and the ground is made of StaticBody2D tiles. Here is the player movement script:

func _input(flipGravity):
    
    if Input.is_action_pressed("flipGravity") and gravityFlipped == true:
        motionVector.y = 0
        gravityFlipped = false;
        get_node("player/playerSprite").set_flip_v(false)
        motionVector = Vector2(speed, gravity)
    
    elif Input.is_action_pressed("flipGravity") and gravityFlipped == false:
        motionVector.y = 0
        gravityFlipped = true;
        get_node("player/playerSprite").set_flip_v(true)
        motionVector = Vector2(speed, -gravity)

func _fixed_process(delta):
    var playerPosition = get_node("player").get_pos()
    playerPosition += motionVector * delta
    
    get_node("player").set_pos(playerPosition)
    
    speed += 0.01
:bust_in_silhouette: Reply From: VitaZheltyakov

Do not increase the gravity higher than 50 …

Increase the fps of the physical engine in the settings.

This sadly does not work, as I would need to set the fps so high that it starts to cause performance issues to get the gravity high enough. I also tried increasing the gravity variable after setting the fps higher, that had a slight effect but not strong enough.

Sigma-One | 2017-07-30 12:30

:bust_in_silhouette: Reply From: Sigma-One

I managed to solve this myself by instead of changing the player position I modify the object’s gravity scale. This also adds some difficulty to the gameplay, which is nice.

:bust_in_silhouette: Reply From: YeOldeDM

The problem is you’re setting the player’s position, and not actually moving them.
set_pos() teleports the object to that position, and does not consider collision/physics while doing so.

To move your rigidbody, use set_linear_velocity() or apply_impulse. Though it’s not a good idea to move a rigidbody this way in _fixed_process. Your best bet is to enable Custom Integration and move your player within that.