+1 vote

hello

i've used godot for some time, but still am mostly a nooblet

having set up a lil tank, and getting it to shoot lazers, i proceeded to make them disappear upon hitting an obstacle. strangely enough, something goes wrong the moment body_enter signal is called.

i get this error (it doesn't crash the game thou):
error calling method from signal (body_enter), expected 0 arguments

it's really weird because the brackets in the "_hit()" function are empty (i assume this is where arguments usually reside?)

code, the object is an Area2D (sorry for raw paste, but i cant get the code frame thingy to work)

func ready():
connect("body
enter",self,"_hit")

func process(delta):
v=Vector2(vbsin(r)delta,vbcos(r)delta)
set
rot(r)
getnode('sprit').setglobalpos(self.getglobal_pos().floor())

func hit():
queue
free()

i used the body_enter signal many times in the past and this has never happened, so am quite confused. :<

in Engine by (15 points)
Please, use the "code" button on the QA editor, don't just paste it. To get it working, you should select your code, and then press it. (also, this is markdown, so if you just indent those lines with four spaces..)

1 Answer

+2 votes

body_enter signal has a parameter which hit the body.

body_enter( Object body )

So, you should have parameter at func _hit()

func _hit(target):
    queue_free()
by (9,686 points)
haha thanx!

i forgot about having to write 'body' beetwen the brackets... although then shouldn't the error say 'expected 1 argument' instead of zero arguments? xD
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.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.