Click to move or interact

Godot Version

v4.2.1.stable.official [b09f793f5]

Question

Hey all,

I am facing an issue when trying to implement some basics for my point and click game.

I have a simple movement mechanic, where the character moves around by clicking.
But then I want to be able to click items on the screen that also interact with the movement mechanic (such as blocks it completely, or makes the character goes toward the objects, stops and the items does something).

I am not sure about the best way to handle this. I’ve looked into the idea behind inherintance vs composition and other ideas, but I am very unsure how to approach it from a more broad point of view. (I want to avoid spaghetti code as much as possible haha)

So in summary, I need to be have to discern what I am clicking and then make a choice about what to do.

Thanks!

And your question is…?

My question is are there any tutorial or convention on how to handle a classic point and click game, where you need to move the character with the mouse, but also handle when you click objects.

So say I click a shelf, I want to character not just to walk in that direction, but it should then decide what to do from the objects point of view.

Hi!
I have a comparable issue and the problem is that most tutorials only show immediate reactions to user input while point&click sometimes requires a sequence of actions:

  • identify click target
  • move to target (if possible)
  • position player sprite in a specific angle towards the object
  • do some checks like: can the object be interacted with? what type of interaction does the player actually want?
  • run animation
  • update game state

Something like this is also tricky for me to implement. So, I am using a rectangle, like a Area2D and a collision rect to determine what has been clicked on using a signal. Then I adjust the target destination of the sprite to the center of the rectangle and move the sprite to that location. The sprite emits another signal upon arrival and I use this to start the checks and the follow-up logic.
I feel this is more natural in a procedural programming language but if we keep track of our event chains then it’s definitely doable.

1 Like

As @VBe already mentioned: The way to go here would be to create an Area2D node (which is input_pickable by default), add a CollisionShape2D (or CollisionPolygon2D) as its child node and then connect the area’s input_event signal to the actual code that determines what happens on certain inputs.

I feel it should also be mentioned here that there are two dedicated frameworks for making Point & Click games in Godot that you might want to take a look at:

1 Like

Thanks for sharing the links!
This does sound promising at first glance!

Amazing, thank you both for your responses. Definitely going to check out those frameworks.

1 Like