Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | NotADuck | |
Old Version | Published before Godot 3 was released. |
Hello, I’m having some trouble with the Rigidbody2d class and its get_colliding_bodies 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.