![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | Kurizu78 |
I’m learning Godot using Godot Engine Game development projects and I came across this code that bugs me. It’s from chapter 4 “Space Rocks”. I am instancing a scene called rock
in the main scene using export (Packed scene)
. The rock
scene has a code to explode when the player shoot it
I connected an exploded
signal in the main scene
func spawn_rock(size, pos=null, vel=null
var r = Rock.instance()
$Rocks.add_child(r)
#Rocks is a child note of the main scene
#I'm using Rocks node as a container for the rock scene
r.connect("exploded", self, "on_Rock_exploded")
Then connected the function _on_Rock_exploded
The _on_Rock_exploded
was suppose to explode the rock and split it into two but when I run it doesn’t happen. And then debugger showed this emit_signal: Error calling method from signal 'exploded': 'Node(Main.gd)::on_Rock_exploded': Method not found
I tried everything but it always show that error. I don’t know what to. Please Help
The code for the _on_Rock_exploded is below
func _on_Rock_exploded(size, radius, pos, vel):
if size <= 1:
return
for offset in [-1,1]:
var dir = (pos - $Player.position).normalized().tangent() * offset
var newpos = pos + dir * radius
var newvel = dir * vel.length() * 1.1
spawn_rock(size -1, newpos, newvel)