#How to manage interactions?

1 messages · Page 1 of 1 (latest)

stable stone
#

I've been trying to come up with a compositing way to make my player be able to interact with any object via a raycast but i'm not really sure how to do that. I've come up with the following logic for now (check image, yes i'm on my phone cuz not at home rn) but not really sure if that'd work well

dense willow
#

Yeah seems pretty sensible

#

My approach would be this:

InteractibleObject (can be anything)
  InteractionArea (custom class that extends Area2D)
#

Then the player does :

func _on_raycast_area_collided(area: Area2D):
  if area is InteractionArea:
    area.interact(self)
#

The area is like :

class_name InteractionArea extends Area2D

signal interaction(source:Node)

func interact(source : Node):
  interaction.emit(source)
  
#

And then the parent Node of the area can react to the interaction signal, check the type of the source, etc.

#

This way you avoid relying on groups, which are not type safe, and the system stays very flexible

stable stone
#

I see, yeah that seems a bit more streamlined that what i had, i'll try and implement that as soon as i'm home, thank you very much