Hello, I'm trying to make a checkpoint for my game, but I don't want the sound for it to play every time you collide with it. This is what I have so far:

# Player Script
func _on_Checkpoint_body_shape_entered(_body_id, body, _body_shape, area_shape):
	     var collision_pos = shape_owner_get_owner(shape_find_owner(area_shape)).global_transform.get_origin()
	     checkpoint = collision_pos
	     $Sound/Checkpoint.play()

EDIT:
I have multiple checkpoints in different scenes (the checkpoint is also a scene instance), and I have them all send the event to the same method.

  • duane replied to this.
  • The easiest way to do that is with a flag.

    var flag = false
    func _on_Checkpoint_body_shape_entered(_body_id, body, _body_shape, area_shape):
    	if not flag:
    		flag = true
    		var collision_pos = shape_owner_get_owner(shape_find_owner(area_shape)).global_transform.get_origin()
    		checkpoint = collision_pos
    		$Sound/Checkpoint.play()

    The easiest way to do that is with a flag.

    var flag = false
    func _on_Checkpoint_body_shape_entered(_body_id, body, _body_shape, area_shape):
    	if not flag:
    		flag = true
    		var collision_pos = shape_owner_get_owner(shape_find_owner(area_shape)).global_transform.get_origin()
    		checkpoint = collision_pos
    		$Sound/Checkpoint.play()

      duane
      It doesn't work because I have multiple checkpoints in different scenes (the checkpoint is also a scene instance), and I have them all send the event to the same method. Basically, I don't want to right:

      var flag1 = false
      func _on_Checkpoint1_body_shape_entered(_body_id, body, _body_shape, area_shape):
      	if not flag1:
      		flag1 = true
      		var collision_pos = shape_owner_get_owner(shape_find_owner(area_shape)).global_transform.get_origin()
      		checkpoint = collision_pos
      		$Sound/Checkpoint.play()
      var flag2 = false
      func _on_Checkpoint2_body_shape_entered(_body_id, body, _body_shape, area_shape):
      	if not flag2:
      		flag2 = true
      		var collision_pos = shape_owner_get_owner(shape_find_owner(area_shape)).global_transform.get_origin()
      		checkpoint = collision_pos
      		$Sound/Checkpoint.play()

      etc.

      P.S. I edited the post

      If they're separate instances, they have separate parameters, so that shouldn't be an issue. Maybe it would help if you linked a subset of your project.

      I forgot to mention that the checkpoint code is my player script, so it doesn't create a new instance of the method each time, so what I decided to do instead is move the sound code to the checkpoint script since that doesn't need to be communicated to the player, and the checkpoint can be changed a million times without the game play being interupted.

      # Checkpoint script
      var checked = false
      func _on_Checkpoint_body_entered(_body):
      	if not checked:
      		$Sprite.texture = load("res://assets/images/objects/checkpoints/checkpoint_checked.png")
      		get_parent().get_parent().get_node("Player/Sound/Checkpoint").play()
      		checked = true
      # Player Script
      func _on_Checkpoint_body_shape_entered(_body_id, _body, _body_shape, area_shape):
      	var collision_pos = shape_owner_get_owner(shape_find_owner(area_shape)).global_transform.get_origin()
      	checkpoint = collision_pos