Is it possible to get colliding object with Kinematic body without move_and_collide?

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

So short description of my game I have segments where a character can move
and big amount of “negative” space where the character will die.
So I made this path out of kinematic objects and use test_move and then move character manually in code.
So if test_move return false character is dead and if it’s true I move the character.
And it works okay but now I want to add pickups.
I know maybe I can use raycasts but maybe I miss something?
Is there some way to get a type of a colliding object from test_move or something else?

:bust_in_silhouette: Reply From: Dlean Jeans

This is what I would do in my game:

  • Add a pick_up_coin in the Player scene script, example:
    func pick_up_coin():
      coin += 1
      score += 100
  • Create a scene for pickups as an Area2D scene
  • Setup collision_layer and collision_mask to detect only the player (optionally but recommended)
  • Connect body_entered signal of the Pickup scene:
    func _on_body_entered(body):
      if not body is Player: return # if you don't setup collision layer and mask
      body.pick_up_coin()

For bullets and projectiles you can do the same but with take_damage in the Player script:

func take_damage(damage):
  self.health = max(0, health - damage)

and in the projectile script:

func _on_body_enter(body):
  body.take_damage(damage)