My code is not working correctly, please help.

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

Im following a tutorial that is slightly out of date i think, but I have been stuck on this for a long time. This is my code:

extends CharacterBody2D

var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")
var player

func _physics_process(delta):
	#crab gravity
	velocity.y += gravity * delta
	
	move_and_slide()

func _on_player_detection_body_entered(body):
	if body.name == "Player":
		player = get_node("../../player")
		var direction = (player.position - self.position)
		if direction.x > 0:
			
			print("right")
		else:
			print("left")

Whenever I run it I get this error:

E 0:00:03:0009   emit_signalp: Error calling from signal 'body_entered' to callable: 'CharacterBody2D(crab.gd)::_on_area_2d_body_entered': Method not found.
  <C++ Source>   core/object/object.cpp:1058 @ emit_signalp()

Any idea whats wrong?

Edited to fix forum code formatting…

jgodfrey | 2023-06-25 21:02

I fixed it nevermind.

powerplayerplus | 2023-06-25 21:14

:bust_in_silhouette: Reply From: Patrick_W

It says that your crab.gd is calling a function called

_on_area_2d_body_entered

but that this function does not exist.
Could it be that you renamed the function to

_on_player_detection_body_entered(body)

but the Area2D is still connected to the old function ?