Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | BlackJitsu | |
Old Version | Published before Godot 3 was released. |
I have the following line in my code I’m trying to use to add a node to a Node2D base node within my game
var paddle_one_node = paddle_one_scene.instance()
paddle_one_node.set_name("PaddleOne")
paddle_one_node.set_pos(Vector2(25, 300))
add_child(paddle_one_node)
I get an error, however, whenever I load the scene stating that set_pos() is a nonexisting function within the KinematicBody2D class. How do I set the position of this node? I’m new to this.
You need to provide more information. What is the “paddle_one_scene” and how is it loaded? Are you by any chance using Godot 3.0?
kidscancode | 2017-10-28 20:40
What kind of node is the root of the scene paddle_one
?.
eons | 2017-10-28 20:46
replace the set_pos
line with:
paddle_one_node.position = Vector2(25,300)
that is because in godot 3 they replaced the set_pos and get_pos with position, giving you instant access to the variable itself
rustyStriker | 2017-10-28 20:56
I am using Godot 3 right now (Not Sure the date on this one) and here is the code I used to load the scene.
var paddle_one_scene = load(global.game.player_one_paddle)
BlackJitsu | 2017-10-28 21:01
Oh ok. Thanks! Didn’t realized they changed that in Godot 3.
BlackJitsu | 2017-10-28 21:02