0 votes

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:                   
Godot version 3.5.1
in Engine by (12 points)

Your indentation doesn't look right.

Normally you move RigidBody's with moveandslide().

1 Answer

0 votes

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.

by (14 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.