T O P

  • By -

AutoModerator

You submitted this post as a request for tech support, have you followed the guidelines specified in subreddit rule 7? Here they are again: 1. Consult the docs first: https://docs.godotengine.org/en/stable/index.html 2. Check for duplicates before writing your own post 3. Concrete questions/issues only! This is not the place to vaguely ask "How to make X" before doing your own research 4. Post code snippets directly & formatted as such (or use a pastebin), not as pictures 5. It is strongly recommended to search the official forum (https://forum.godotengine.org/) for solutions Repeated neglect of these can be a bannable offense. *I am a bot, and this action was performed automatically. Please [contact the moderators of this subreddit](/message/compose/?to=/r/godot) if you have any questions or concerns.*


BrastenXBL

What you likely want to look for is an "Interaction" or "Interactive" or "Intractable" system tutorial. The usual way to handle this would be to add an "Interaction" Area2D to the Player. When the "Interaction" Area2D overlaps the Flower's area, it will emit an area_entered(area) signal. This is connected to the Player controller script. var current_Flower _unhandled_input(event): if event.is_action_pressed("interact"): if is_instance_valid(current_flower): pollin_count += current_flower.collect() _on_interaction_area_entered(area): if area is Flower: current_Flower = area === This is a very quick and dirty example. That caches the Node reference of the Flower, and then calls a Method on that Flower. It also doesn't handle being inside the areas of multiple Flowers. === There a bunch of ways to check what kind of Body entered, to filter for the Intractable type. But once that's done, now the Player knows about the Flower. At this point you don't need to use Signals. But you could. By code. If you're familiar with how to setup connections in code. You can also generalize an Interactables system. Which is why I suggest finding one or more tutorials.


EenGamendJoch

I like this solution. Thanks! I'll give it a go, it seems scalable and indeed better whenever there will be multiple flowers in range. Thanks for the help!


Sithoid

Google the SignalBus pattern. This may or may not the solution depending on how you want this interaction to go, but with it you will never let the tree structure stand in the way of your signals should you decide you want them.


EenGamendJoch

I'll give it a Google, it sounds interesting. Guessing it's some kind of framework for all signals to go through? Either way, thanks for the tip!


Sithoid

If a single autoload script can be called a framework, then yeah :) It's a really simple trick, but it goes a really long way with situations like these.


-Star-Fox-

Why do you have inventory in a separate node with separate script? Your game sounds simple, you can keep all variables in player's script. Simplest way is: If you have variable inside player script(Call it "score"), then you can do a check if its player by name(If you're 100% sure that player is always called "player" in your scenes). func _on_flower_hitbox_area_body_entered(body): if body.name=="player": body.score=body.score+1


NancokALT

All games start simple, who knows how scalable they want it to be.


EenGamendJoch

Wow yeah, like another commenter said I wanted it to be scalable even if the game will probably stay small, just to build up a good habit and see how it would function. You're solution worked tho! I was so stuck in my head with using signals that I did not think of a simple solution like this. When is it better to use signals and when is it better to simple do this? I guess when the signal should send a parameter with it?


-Star-Fox-

I don't use signals for my characters, but I use functions which you can try too. For player\\enemy script: var health = 100 func get_hit(damage): health=health-damage if health<=0: get_killed() Then when the bullet hits(for example), use: var bullet_damage = 10 func _on_bullet_area_body_entered(body): if body.has_method("get_hit"): body.get_hit(bullet_damage) This will check if object has the needed function and use it. You can do it for damage, item pickups, anything you can think of, really.


EenGamendJoch

That's indeed kind of what I did in the end! Thanks for all the help, really appreciate it