+1 vote

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?

in Engine by (28 points)

1 Answer

+1 vote
Best answer

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)
by (4,209 points)
selected by
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.