I need something to know is player in area2d

Godot Version

Godot 4


First of all I have a bad english sorry for that.

I have a scene like that when my body entered area mob follows or when body exited mob stops etc. but when my mob respawn mob didnt followed bcs I used body_entered and body_exited codes when mob respawned if player in area mob didnt know it so its playing idle


if not global.mob_alive:
if player_chase and global.mob_alive and global.player_alive:
position +=(player.position - position)/speed

func _on_area_2d_body_entered(body):
player = body
player_chase = true

func _on_area_2d_body_exited(body):
player = null
player_chase = false

Using overlaps_body() instead of signals would be preferable here.

# store the player and area2D references in a variable
var player = $path_to_player #replace with an actual node path!
var area = $Area2D

func _process(_delta):
	if global.mob_alive and global.player_alive and area.overlaps_body(player):
		position += (player.position - position) / speed

how can I take player path this note is mob.gb I cant use player nodes etc

It depends on your node tree, which you never showed. Read up on how node paths work. It’s kinda important for working with godot.

dont be angry man I just too new here my nodes

I am neither angry nor a man. =P
You could use

var player = get_tree().root.get_node("Dunya/CharacterBody2D")

But maybe you want to rename it to Player first?