0 votes

Hello, I'm having some trouble with the Rigidbody2d class and its getcollidingbodies function.
I'm making an endless runner close to Google Chrome's dino just to test out the engine but I'm having some trouble detecting the collisions between the player and the obstacles.
This is my code so far:

func _input(event):
    if event.is_action_pressed("game_jump"):
        speed.y = JUMP_FORCE * (-1)

func _fixed_process(delta):
    speed.x = 0
    speed.y += GRAVITY * delta
    velocity = Vector2(speed.x*delta,speed.y*delta)
    get_node("player").set_linear_velocity(Vector2(speed.x,speed.y))

        if inst != null :
        inst.move(Vector2(-envSpeed,0)*delta)

    print(get_node("player").get_colliding_bodies().size())

    if spawnTimer >= 3:
        inst = load("res://pawns/obstacles/funky_cactus.xml").instance()
        inst.set_global_pos(Vector2(660,300))
        inst.add_to_group("obstacles")
        add_child(inst)
        spawnTimer = 0

    spawnTimer += delta

Basically every time the player spawns it hits the ground and it stays there and get_colliding_bodies().size()is equals to 1 but every time an obstacle comes to the player the size of the array of colliding bodies is always 1.

in Engine by (14 points)

2 Answers

0 votes

Have you set "Contact Monitor" to On and "Contacts Reported" to a value greater than 0?

by (18,209 points)

I have already enabled the "Contact Monitor" and I have set the "Contacts Reported" to 5 (just to be sure)

0 votes

some times, when i try to put in a picture, or a figure in rigidbody2D, i just have to expand it! idk if thats What you are looking for, but thats all i got bro! im new jsyk.

by (43 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 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 webmaster@godotengine.org with your username.

Categories