0 votes

I have a editor tool script that changes the in-game camera position on the map...

I would also like to add functionality to change the Editor's viewport position... where its looking in the map.

To quickly jump around to different pre-set locations.

Only other workaround i can think of is to place a bunch of empty Position3Ds around the map then somehow call the Godot hotkey to center focus on an object?

https://godotengine.org/qa/71284/how-to-focus-on-a-node-object-in-the-editor

Godot version 3.3
in Engine by (16 points)

1 Answer

0 votes

FHeres a hacky workaround I did using a Plugin... there may be a more elegant solution but for now this works.

## place this code in a background plugin in the editor
#
# Then place 4 Spatials around your map with names "NavPoint1" , "NavPoint2" etc..
#

func _unhandled_input(event):

    if event is InputEventKey:
        if event.pressed and event.scancode == KEY_3:
            go_to_node("NavPoint1")
        if event.pressed and event.scancode == KEY_4:
            go_to_node("NavPoint2")
        if event.pressed and event.scancode == KEY_5:
            go_to_node("NavPoint3")
        if event.pressed and event.scancode == KEY_6:
            go_to_node("NavPoint4")

func go_to_node(nodeName):
    var es : EditorSelection = editor_interface.get_selection()
    if es == null:
        print("cant initialize EditorSelection, returning")
        return
    var node_to_nav_to = get_tree().get_edited_scene_root().find_node(nodeName)
    if node_to_nav_to == null:
        print("cant nav to node")
        return

    es.clear()
    es.add_node(node_to_nav_to)
    print("simulating F Key")
    simulate_key(KEY_F)

func simulate_key(which_key ):
    #https://docs.godotengine.org/en/stable/tutorials/inputs/inputevent.html
    print("simulating key %s" % which_key)
    var ev = InputEventKey.new()
    ev.scancode = which_key
    ev.pressed = true
    Input.parse_input_event(ev)
by (16 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.