–1 vote

I have a player node that is an area2d node. I want to be able to move the player around when clicking on the map, and also to be able to interact with other objects. So when I click outside the area2d, the player will walk to the click point. When I click inside the area2d, the player will interact with something. But the player also moves towards the click point. I put get_tree().set_input_as_handled() but it didn't work. What do I do?

Edit: Checked the docs again. Apparently _unhandled_input() is called before the _input_event() function. Not sure if that's really ideal, but I'm not a game engine designer.

in Engine by (6,496 points)
edited by

Might need more info. Are you for sure overriding _unhandled_input instead of _input? Are you using "pickable" for the Area2Ds? (those kinda go through stuff other than unhandled_input and are so it wouldn't help anyway.)

I really wish there were some better way to input code.

func _input_event(_viewport, event, _shape_idx):
    if event.is_action_pressed("click") and can_interact:
        for body in get_overlapping_areas():
            if body.has_method("show_dialogue"):
            elif body.has_method("change_scene"):
            elif body.has_method("add_item"):

func _unhandled_input(event):
    if event.is_action_pressed("click"):
        destination = get_global_mouse_position()
        move_left = destination.x - position.x > 0
        if move_left:
           ray.cast_to = Vector2(50, 0)
           movement = SPEED
           ray.cast_to = Vector2(-50, 0)
           movement = -SPEED
        moving = true

I'm pretty sure I'm going through _unhandled_input instead of _input. The function is called _unhandled_input. I know that both functions are getting called because they both perform their functions correctly (except for the handled input thing).

1 Answer

–1 vote
Best answer

I solved it by just cancelling movement every time the character interacts with something.

by (6,496 points)

Best answer so far thanks self

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.