Collision Detection, Part 2

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

I am having more trouble with collision detection. KidsCanCode advised me to use body_entered(body) on the Area2D, so I did:

extends Area2D

var speed = -20
var rot_speed = rand_range(0, 0.1)
const dogp = preload("res://DogPlayer.tscn")
var dog = dogp.instance()
var playing = true

func _ready():
	randomize()

func _process(delta):
	if Input.is_action_just_pressed("laser"):
		playing = true
 
func _physics_process(delta):
	var motion = speed
	position.x += motion
	$Sprite.rotation += rot_speed

func _on_Meteor1_body_entered(body):
	playing = false

and then added something in the playspace where if the meteor’s variable “playing” is false, then the playspace’s variable “playing” was also false:

if meteor.playing == false:
		playing = false

but it doesn’t work. Help? Here is the full code (playspace) if you need it:

extends Node2D

const warning1 = preload("res://Warning1.tscn")
const warning2 = preload("res://Warning2.tscn")
const warning3 = preload("res://Warning3.tscn")
const met = preload("res://Meteor1.tscn")
var meteor = met.instance()
var score = 0
var playing = false
var high_score = 0
var pause = false


func _ready():
	randomize()
	$Timer.start()

func _on_Timer_timeout():
	if playing == false:
		return
	if pause == true:
		return
	randomize()
	var choice = randi() % 3
	if choice == 1:
		var Warning1 = warning1.instance()
		add_child(Warning1)
	if choice == 2:
		var Warning2 = warning2.instance()
		add_child(Warning2)
	if choice == 0:
		var Warning3 = warning3.instance()
		add_child(Warning3) 
	if $Timer.wait_time >= 1:
		$Timer.wait_time -= 0.25

func _process(delta):
	if Input.is_action_just_pressed("laser") and playing == false:
		playing = true
		$Label5.text = ""
		$LinkButton.text = ""
	if Input.is_action_just_pressed("pause"):
		if playing == false:
			return
		if pause == false:
			pause = true
	if pause == true:
		$Label5.text = "Press Space to Resume"
	if Input.is_action_just_pressed("laser") and pause == true:
		pause = false
		$Label5.text = ""
	if pause == true:
		$DogPlayer.velocity.y = 0
	if playing == false:
		pause = false
		$Label5.text = "Press Space to Play"
		$LinkButton.text = "Discord"
	if playing == true and pause == false:
		score += 0.02
	if meteor.playing == false:
		playing = false
	$Label2.set_text(str(score))
	$Label4.set_text(str(high_score))
	if score >= high_score:
		high_score = score


func _on_LinkButton_pressed():
	OS.shell_open("https://discord.gg/eYe3wka")