Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | CyanGhosty |
There is a part in the player’s code where I had to use get node on the player’s sprite. So I wrote it like $Sprite, the sprite node itself is just called Sprite and it worked previously. But now it comes up with an error and says it can’t find it. The sprite node is also a child of the player node.
I’m quite new to Godot and coding in general so I’m not sure if I’m missing something?
Can show post picture of your scene tree.
supper_raptor | 2020-04-05 17:46
Node not found happens if the node from which you use get_node
does not have Sprite
as immediate child. Maybe you moved it one level deeper?
Zylann | 2020-04-05 21:56
No, it’s its immediate child I even double checked just to make sure
CyanGhosty | 2020-04-06 11:26
Can you post your code?
Zylann | 2020-04-06 11:34
else:
motion.x = 0
motion.y = 0
$Sprite.stop()
$Sprite.set_frame(0)
CyanGhosty | 2020-04-06 11:39
Whole code? Or your project, if you can
Zylann | 2020-04-06 12:48
extends KinematicBody2D
var motion = Vector2()
export var speed = 100
func _physics_process(delta):
if Input. is_action_pressed(‘ui_right’):
motion.x = speed
$Sprite.play(“right”)
if Input. is_action_pressed(“ui_run”):
motion.x = speed*2
elif Input. is_action_pressed('ui_left'):
motion.x = -speed
$Sprite.play("left")
if Input. is_action_pressed("ui_run"):
motion.x = -speed*2
elif Input. is_action_pressed('ui_down'):
motion.y = speed
$Sprite.play("down")
if Input. is_action_pressed("ui_run"):
motion.y = speed*2
elif Input. is_action_pressed('ui_up'):
motion.y = -speed
$Sprite.play("up")
if Input. is_action_pressed("ui_run"):
motion.y = -speed*2
else:
motion.x = 0
motion.y = 0
$Sprite.stop()
$Sprite.set_frame(0)
move_and_slide(motion)
Does that help?
CyanGhosty | 2020-04-06 12:54
Not really… at this point I’m still pretty sure your Sprite
has been moved or has a typo in its name. I’d need to see the project.
Also judging by $Sprite.play("down")
, it looks like your Sprite
is actually an AnimatedSprite
(but only the name should matter)
Zylann | 2020-04-06 14:02
So how would I go about sharing the project with you? As I said I’m new to this
CyanGhosty | 2020-04-06 14:46
You can use file transfer: https://send.firefox.com/
Or Google Drive, or Github
Even though I believe your problem is probably something really simple
Zylann | 2020-04-06 14:48
Loop – Google Drive
Like that?
CyanGhosty | 2020-04-06 14:57
I tried opening it but all scripts are empty and Room.tscn
does not open. Looks like it’s not the whole project.
Wait…
You put scripts and assets in the .import
folder? I strongly suggest you don’t do this xD .import
is reserved for cached import files. Godot has a problem loading Room.tscn
for another reason, but because it is in .import
, I can’t fix it because the file explorer does not let me access it in the editor.
Zylann | 2020-04-06 17:10