Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | cleeverz | |
Old Version | Published before Godot 3 was released. |
Hello there!
I’ve built a StaticBody2D body called wall in my little game experiment Godot, that just sits there and blocks collision. It’s working fine.
The next thing I wanted to do was to build a node called wall_ manager that places instances of these walls as a border around the screen. However I’ve run up against this:
Here’s the code just to place one wall:
func _ready():
var wall = wall_scene.instance()
var wall_offset = Vector2(12, 12)
wall.set_position(get_global_pos() + wall_offset)
add_child(wall)
And here is the error produced:
Invalid call. Nonexistent function 'set_position' in base 'StaticBody2D'.
On the one hand, StaticBodies aren’t meant to be moved, so this makes sense, but on the other hand, if I want to put a static body into the game via code, which seems reasonable, this leaves me wondering how.
Is there a way to do this that I’m missing? Or is a StaticBody maybe the wrong construct for this? I could use a Tilemap maybe? But I only have one image right now and that seems like a bulky object and a lot of extra coding to do something as simple as what I’m trying to do.
Thanks for your time!