Dodge The creeps - Player can't collide with Mobs

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

Hi, ive been trying to do the first project from DOCS, I got the project to a playeable state, game launches and run perfect but cant interacts with the mobs.

this is the error i get from the debugger :

E 0:00:09:0772 Error calling method from signal ‘body_entered’: ‘Area2D(Player.gd)::_on_Player_body_entered’: Method not found.
core/object.cpp:1238 @ emit_signal()

and this is my code:
extends Area2D

signal hit


export var speed = 400
var screen_size

func _ready():

screen_size = get_viewport_rect().size
hide()


func _process(delta):

var velocity = Vector2() #Moving the Player
if Input.is_action_pressed("ui_up"):
	velocity.y -= 1
if Input.is_action_pressed("ui_down"):
	velocity.y += 1
if Input.is_action_pressed("ui_left"):
	velocity.x -= 1
if Input.is_action_pressed("ui_right"):
	velocity.x += 1
if velocity.length() > 0:
	velocity = velocity.normalized() * speed
	$AnimatedSprite.play()
else:
	$AnimatedSprite.stop()

position += velocity * delta #limit the player movement to the screen
position.x = clamp(position.x, 0, screen_size.x)
position.y = clamp(position.y, 0, screen_size.y)

if velocity.x != 0:
	$AnimatedSprite.animation = "Right"
	$AnimatedSprite.flip_v = false
	$AnimatedSprite.flip_h = velocity.x < 0
elif velocity.y != 0:
	$AnimatedSprite.animation = "Up"
	$AnimatedSprite.flip_v = velocity.y > 0



func on_player_body_entered(Rigidbody2D):
hide()
emit_signal("hit")
$CollisionShape2D.set_deferred("Disabled", true)

func start(pos):
position = pos
show()
$CollisionShape2D.disabled = false

I tryed to disconnect all signals and reconecting them again. but didnt find the mistake.

if you need any other code from other scenes, can pass them too.

THANK YOU!

Remember: everything here is case-sensitive.

System_Error | 2019-11-15 04:38

:bust_in_silhouette: Reply From: kidscancode

The error message says it couldn’t find _on_Player_body_entered(). Which makes sense, because in the script, you have the function named on_player_body_entered().

Note that if your node is named Player, connecting the signal will automatically create the function with the name _on_Player_body_entered(). You don’t have to type it out.

In addition, the parameter passed by the signal is the body that was collided. By default, the variable name used is body. It’s not clear why you changed that name too.