Moving the player object manually after collision (2D)

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

So I’m trying to do the following:

  1. Activate a CollisionShape2D
  2. If it collides with an object, move the player object up one unit at a time until there is no more collision

But even after I move the object for multiple loops, the collide()-function still detects a collision and it becomes an endless loop. Can anybody tell me what I’m doing wrong? Is there a better way of moving an object upwards on collision?

func _on_FloorDetect_body_shape_entered(body_rid, body, body_shape_index, local_shape_index): 
    if body is TileMap:	
        var tilemap = body as TileMap
        var coordinate: Vector2 = Physics2DServer.body_get_shape_metadata(body_rid, body_shape_index)
        var tileid = tilemap.get_cellv(coordinate)
        var shape = shapes[0]["shape"]
        var otherTrans = shapes[0]["shape_transform"]    

        if IdleCollision.disabled:
            IdleCollision.disabled = false
            var colliding = false
            while true:
            var trans = IdleCollision.transform
            colliding = IdleCollision.get_shape().collide(IdleCollision.transform, shape, otherTrans)
            if colliding:					

Your indentation doesn’t look right.

Normally you move RigidBody’s with move_and_slide().

SteveSmith | 2023-01-22 12:13

:bust_in_silhouette: Reply From: tommypatel

Hello, I wanted to say that you may try another way of programming. Maybe you would try the function method. I will ask for help from my friend who works as a programmer he helped me to do my excel project and graphics for it. Personally for me, it would be hard to understand and do.