Hello
I’m new to Godot and try to get some basics, but I can’t answer to my question.
I try to spawn object to scene by mouse clicking.
But unfortunately it doesn’t work for me.
I have main scene (World.tsc) and here I have a script
var road = preload("res://Main/Resources/Road.tscn")
func make():
var instance = road.instantiate()
instance.global_position = Vector3(0, 0, 1)
add_child(instance)
I call it from camera script
extends Camera3D
var mouse = Vector3()
var createRoad = preload("res://Main/createRoad.gd").new()
func _input(event):
if event is InputEventMouse:
mouse = event.position
if event is InputEventMouseButton and event.is_pressed():
if event.button_index == MOUSE_BUTTON_LEFT:
spawnRoad()
func spawnRoad():
var position2D = get_viewport().get_mouse_position()
print(mouse)
createRoad.newPosition = mouse
createRoad.make()
Unfortunately it don’t do anything. I can make breakpoint on it(I know I don’t use mouse position, but I remove that to test).
When I try for example using that i main script
func _physics_process(delta):
if Input.is_action_just_pressed("left_click"):
var instance = road.instantiate()
instance.global_position = Vector3(0, 0, 1)
add_child(instance)
It’s works okey
When I try call make() func in _ready() it’s works too.
How can I fix that and spawn object by clicking on screen from Camera script?
It’s working now after I add Root to camera.gd
But I have one question.
You StageHandler is some your custom interface, or this is common in Godot?
Because I have it here