Area2d isnt detecting player

Godot Version

4.3

Question

Hello, im fairly new to godot and I am trying to create scene transitions between different levels, However the area2d is not detecting the player when they collide and so the scenes arent transitioning. I have redon my collision layers and i am fairly sure they shoudd work however the area2d which is tryng to detect the player isnt. Any help would be greatly apprceiated.

extends Node2D
@onready var pauseMenu = $"Main/Entities/Player/Pause menu"
var paused = false 

func _ready():
	$Fade/AnimationPlayer.play("Fade_out")

func _process(delta):
	if Input.is_action_just_pressed("pause"):
		pausemenu()
		
func pausemenu():
	if paused:
		pauseMenu.hide()
		get_tree().paused = false
	else:
		pauseMenu.show()
		get_tree().paused = true
	paused = !paused

func _on_scene_transition_detection_body_entered(body : Node2D) -> void:
	if body is player:
		print(body)

this is the level code with the transition signal, i havent implemnetd the actual scene transition as the body sint being printed so it wouldnt work

extends CharacterBody2D

class_name player

@onready var animation_tree : AnimationTree = $AnimationTree
@onready var sprite : Sprite2D = $Sprite2D
@onready var state_machine : CharacterStateMachine = $characterstatemachine

@export_group("move")
@export var speed: int = 200
@export var acceleration := 700
@export var friction := 10000
var direction := Vector2.ZERO
var can_move := true
var dash := false
@export_range(0.1,2) var dash_cooldown := 0.5
var gamepad_active := true


@export_group("jump")
@export var jump_strength := 300
@export var gravity := 600
@export var terimnal_velocity := 500
var jump := false
var faster_fall := false
var gravity_multiplier := 1

func _ready():
	$Timers/DashCooldown.wait_time = dash_cooldown
	animation_tree.active = true
	

func _process(delta):
	apply_gravity(delta)
	if can_move:
		get_input()
		apply_movement(delta,state_machine)
		update_animation()
		update_facing_direction()

func update_animation():
	animation_tree.set("parameters/move/blend_position",direction.x)

func update_facing_direction():
	if direction.x > 0:
		sprite.flip_h = false
	elif direction.x < 0:
		sprite.flip_h = true

func get_input():
	#horizontal movement
	direction.x = Input.get_axis("Left","Right")
	
	#jump
	if Input.is_action_just_pressed("Jump"):
		if is_on_floor() or $Timers/Coyote.time_left:
			jump = true
			
			if velocity.y > 0 and not is_on_floor():
				$Timers/JumpBuffer.start()
			
	if Input.is_action_just_released("Jump") and not is_on_floor() and velocity.y < 0:
		faster_fall = true
	#dash
	if Input.is_action_just_pressed("dash") and velocity.x and not $Timers/DashCooldown.time_left:
		dash = true
		$Timers/DashCooldown.start()
		
		
	var aim_input_gamepad = Input.get_vector("Left","Right","up","down")
	#if aim_input_gamepad.length() > 0.5:
		#aim_direction = Vector2(round(aim_input_gamepad.x),round(aim_input_gamepad.y))
		
		
		
		
func apply_movement(delta,state_machine):
	#left/right movement
	if direction.x && state_machine.check_if_can_move():
		velocity.x = move_toward(velocity.x, direction.x * speed, acceleration * delta)
	else:
		#introduces friction in order to stop player if there is no input
		velocity.x = move_toward(velocity.x, 0, friction * delta)
		
	#jump
	if jump or $Timers/JumpBuffer.time_left and is_on_floor():
		velocity.y = -jump_strength
		jump = false
		faster_fall = false
		
	var on_floor = is_on_floor()
	move_and_slide()
	if on_floor and not is_on_floor() and velocity.y >= 0:
		$Timers/Coyote.start()
	
	
	
	#dash
	if dash:
		dash = false
		var dash_tween = create_tween()
		dash_tween.tween_property(self, 'velocity:x',velocity.x + direction.x * 600,0.3)
		dash_tween.connect("finished",on_dash_finish)
		gravity_multiplier = 0
	
func apply_gravity(delta):
	velocity.y += gravity * delta
	velocity.y = velocity.y / 2 if faster_fall and velocity.y < 0 else velocity.y
	velocity.y = velocity.y * gravity_multiplier
	velocity.y = min(velocity.y, terimnal_velocity)
	
	
func on_dash_finish():
	velocity.x = move_toward(velocity.x,0,500)
	gravity_multiplier = 1

this is the player script, the class name is player so it shoudl be working

I can attach anyore dteials if needed, Thank you

Can you show us how you define your area2D collision and mask layers and same for the player ?

1 Like


this is the players collision layer and mask layers

the mask layer for the detection area 2d is one 2 so it should be able to detect the player but im not sure why it wont

edit

After doing some more testing i discovered that the area2d shows upa nd does work only when i run current scene, when i run the porject it doesnt work. I am not sure how to fix this but porgress is being made!

It could be that the scenes have different collision layers and masks saved. Go to the scene itself and set the appropriate configuration and save. Then go into each scene that imports the scene and make sure the default settings are used for layer and mask.

Maybe you got something in your layers/masks mixed up? If you connected the signal from UI it should work :thinking:

Check out this tip about layers and masks

thank you for your repsonse. After reading this I decidied to go back and make sure each layer and mask wa scorrect as i negelected this at the begining of the projcect. I am quite sure that tey shoul working as now the area2d shows up and wors when i run current scene and doesnt work when i run the enitre project im not sure why

Thank you for responding. I chcked the scne itself nd i didnt see any collsion layers However I changed the visibilty layers and it didnt change anything, the area 2d only works when i run current scene and not the entire project. Do you have any insight on why this is happening?

That’s was my only thought, it would only make sense if the project scene has a collision layer/mask override saved on it. All scene instances of the player and area in the project scene need to be checked. And the project scene doesnt manipulate the layer/mask dynamically in a script.

i guess if the detection signal is connected dynamically does the project scene do that?