Advertisement
scolain

Godot 4 TDS fire and die

Oct 27th, 2023 (edited)
1,120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ##########################################################
  2. # IMPORTANT!!
  3. # Coller ce code À LA FIN du fichier Player.gd
  4. ##########################################################
  5.  
  6. func fire():
  7.     var bullet_instance = bullet.instantiate() as Bullet
  8.     bullet_instance.position = get_global_position() + (Vector2.from_angle(rotation) * 25)
  9.     bullet_instance.rotation_degrees = rotation_degrees
  10.     bullet_instance.apply_impulse(Vector2(bullet_speed, 0).rotated(rotation))
  11.     bullet_instance.realName = "Bullet"
  12.     get_tree().get_root().call_deferred("add_child", bullet_instance)
  13.  
  14. func _on_area_2d_area_entered(area):
  15.  
  16.     #if "Enemy" in area.get_parent().name :
  17.     if area.get_parent() is Enemy :
  18.         var _tmp = get_tree().call_deferred("reload_current_scene")
  19.         player_died.emit()
  20.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement