0 votes

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 'bodyentered': 'Area2D(Player.gd)::onPlayerbodyentered': Method not found.
core/object.cpp:1238 @ emit

and this is my code:
extends Area2D

signal hit

export var speed = 400
var screen_size

func _ready():

screen_size = get_viewport_rect().size

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

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):
$CollisionShape2D.set_deferred("Disabled", true)

func start(pos):
position = pos
$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.


asked Nov 14, 2019 in Projects by N00b (66 points)

Remember: everything here is case-sensitive.

1 Answer

0 votes

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.

answered Nov 15, 2019 by kidscancode (17,702 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.