Interact with Objects in your World in Godot 4

แชร์
ฝัง
  • เผยแพร่เมื่อ 7 พ.ย. 2024

ความคิดเห็น • 99

  • @Phosphor_screen.
    @Phosphor_screen. 9 หลายเดือนก่อน +28

    when he says like button the like button does a thing

  • @RickyRicardo1117
    @RickyRicardo1117 11 หลายเดือนก่อน +19

    If you're having issues not seeing the interactable signals at 7:30 (I'm on 4.2rc1 and could not find them), restart godot and they should show up.

  • @kalaris11
    @kalaris11 6 หลายเดือนก่อน +2

    Criminally under-rated channel, 2 of your videos saved me a hundred hours of learning -- and this interaction system is superior to anyone else's, -- most people try to do it with ray casts -- I implemented this in my own project weeks ago, and came back just to say how helpful it was.

  • @OhBoy_IWasUsingMyRealName
    @OhBoy_IWasUsingMyRealName 8 หลายเดือนก่อน +1

    Ayyo. Thanks so much for this tutorial. I hate not being able to come up with these things myself but I am so glad I watched. I am sure I would have gotten here eventually but you saved me days of fixing anti-patterns and bad un-reusable code. Thank you. I love you. Keep doing this stuff you are great at it.

  • @TheRealKaiProton
    @TheRealKaiProton ปีที่แล้ว +4

    that was great!
    Will be coming back to this channel for future videos,
    I especially liked the little "miss Matched assets" joke, I think we have all been there at some point.

  • @jasonleeroberts
    @jasonleeroberts 5 หลายเดือนก่อน +4

    Could you please walk through the other functions/how to set up the omnilight/highlight for the chest scene?

  • @somethingc00l1
    @somethingc00l1 8 หลายเดือนก่อน

    OH MY GOD THIS HELPED SO MUCH! i've been having a problem with setting up interactable objects for 3 days and this finally worked! 🙏🙏🙏🙏🙏🙏

  • @salt2947
    @salt2947 ปีที่แล้ว +1

    This the type of snazzlepackle im trna see a nice quick and simple tutorial ty frfr

  • @Velnias75
    @Velnias75 22 วันที่ผ่านมา +1

    Eureka! I can open the entrance door now on my prototype 😺

  • @schleicher47able
    @schleicher47able 9 หลายเดือนก่อน

    great tutorial! implemented it for picking up items. very nice! just had a little fix to make to prevent the game from crashing after picking up a single item and deleting it from the scene. besides that everything worked just fine! 🤩

  • @jeremisaarinen8569
    @jeremisaarinen8569 6 หลายเดือนก่อน +1

    Thank you for the great tutorial! Such a clean implementation. I modified it a little for my game to use RayCast3D in first person, but it works wonders. Now to add thousands of interactable buttons!

    • @darmawanrendy4481
      @darmawanrendy4481 6 หลายเดือนก่อน

      how to change it to ray cast ?

    • @jeremisaarinen8569
      @jeremisaarinen8569 6 หลายเดือนก่อน

      @@darmawanrendy4481 Under PlayerInteractor scene I added the Raycast, remember to change its collision mask to interactions, and then in PlayerInteractor script you can use is_colliding() and get_collider(), this is what mine looks like for example:
      if ($RayCast3D as RayCast3D).is_colliding():
      var detected :Object = ($RayCast3D as RayCast3D).get_collider()
      if detected is Interactable:
      player_target = detected
      focus(player_target)

  • @wukerplank
    @wukerplank 9 หลายเดือนก่อน

    Such a good tutorial that also focuses on the reusability of the component! I tried first to have a raycast for the interactor, but figured out that it cannot detect Area3Ds.

    • @sirgrem2988
      @sirgrem2988 8 หลายเดือนก่อน +1

      Pretty sure raycast has an option in the properties panel to make it detect Areas instead of just bodies.

  • @davidj3048
    @davidj3048 13 ชั่วโมงที่ผ่านมา

    Like to see more videos from you they are really good!

  • @Soroosh.S83
    @Soroosh.S83 10 หลายเดือนก่อน +1

    Lmao this is the funniest thumbnail and overall theme for the video and especially the majima 😂

  • @ElGhost-p6t
    @ElGhost-p6t หลายเดือนก่อน +1

    Damn, thanks for your tutorial, do you know how to do that mechanic of holding on to the wall to spy stealf style like Outlast? I know it's a random question, but I really need this mechanic.

  • @majohime
    @majohime ปีที่แล้ว +1

    Another day of dreaming when they actually add stencil buffer into Godot 4 to create cute outlines instead of that ugly inverse hull method.
    Thanks for good tutorial.

  • @mrdadox
    @mrdadox 6 หลายเดือนก่อน

    you´re a genius, thank you!!

  • @mikeg.5140
    @mikeg.5140 6 หลายเดือนก่อน

    Great video. Thanks for sharing.

  • @DuriniOnline
    @DuriniOnline 10 หลายเดือนก่อน +3

    Hello, I followed your tutorial as outlined in the video, and for each of the signals I have the engine print a message. When I lose focus, it is triggered twice, while gain focus and interact is only triggered once. Do you have any ideas on why this may be and how I can fix it?

    • @DuriniOnline
      @DuriniOnline 10 หลายเดือนก่อน +2

      it seems like this bit of code is causing the unfocus to be called twice is once from the _physics process and once from the _on_area_exited:
      I commented out the unfocus call in the _physics_process for the Player Interactor and the unfoucs was only called once. I am not sure if this is a good fix or not.
      if new_closest != cached_closest:
      if is_instance_valid(cached_closest):
      unfocus(cached_closest)

  • @Snorth_3D
    @Snorth_3D ปีที่แล้ว

    Fantastic, just what I was looking for 🥳

  • @jettt10
    @jettt10 ปีที่แล้ว

    Man nice work keep making videos helps a lot

  • @phoenixastra4429
    @phoenixastra4429 3 หลายเดือนก่อน +1

    It's saying I can't convert cast area 3d with "closest = interactable as Interactable" line, does anyone know what this is?
    for reference my code is exactly same in the tutorial, the layers, the project setting layer 2, made sure it matched up with exact measurements and area3ds, names, and boxshapes, still give me that error. Using 4.2 stable

  • @Retro-Coolkid735
    @Retro-Coolkid735 4 หลายเดือนก่อน +2

    In the Interactor script, I get an error that says: Invalid cast. Cannot convert from "Area3D" to "Interactable". Does anyone know the solution to this?

    • @phoenixastra4429
      @phoenixastra4429 3 หลายเดือนก่อน

      same issue

    • @madcapmexican4401
      @madcapmexican4401 2 หลายเดือนก่อน

      If I recall you need to change your interactable script to extend from Area3D. I had the same issue and realized I didn't make that change either when I made the script, but it was done in the video

  • @martinithechobit
    @martinithechobit 11 หลายเดือนก่อน

    Thanks yall.

  • @jakekingston5075
    @jakekingston5075 5 หลายเดือนก่อน

    This is really awesome. I'm just wondering, could one extend this to picking an object up and having that object attach to an anchor point on the player? I've got a little raccoon and I want him to be able to carry objects in his mouth. Would you need an extra signal for when you have a held item that prevents you from interacting with anything else? In there I'm imagining you could set the interactable to whatever is currently being held, and hitting interact again would drop the item? Just trying to imagine how to structure it all, it's kind of state machine-y. But regardless, thank you for the tutorial, super helpful!

  • @shajidhossain10
    @shajidhossain10 ปีที่แล้ว +2

    Very well structured and helpful tutorial. Thank you!

  • @halimghani
    @halimghani ปีที่แล้ว

    Very nice

  • @mae3002
    @mae3002 6 หลายเดือนก่อน

    I've followed the tutorial to the letter with the slight alteration of changing out the character controller reference for a rigidbody3d as I just have a capsule player at the moment. And despite checking and recchecking my collision layers and maps, the function get_overlapping_areas() returns an empty list always. I'm not sure what to try next as I'm fairly new to godot.

    • @flynsarmy
      @flynsarmy  6 หลายเดือนก่อน

      There's a demo repo in the description you can download where everything should be working. Give that a try and compare it to your current project.

  • @ethancline9695
    @ethancline9695 6 หลายเดือนก่อน

    Great tutorial video, in fact this is the only one I could find to help me solve my problem! The only thing is I'm getting an error in my Interactor base class's get_closest_interactable function where I try to cast interactable as an Interactable type. It says I can't convert from Area3D to Interactable, but I even tried using your script verbatim and I still got the error. Any ideas?
    Edited to say: I think I solved it, for some reason I created the Interactable node as a child of Node3D instead of Area3D. After I fixed it, saving and closing followed by reopening the project made the error go away.

  • @ouesh35
    @ouesh35 ปีที่แล้ว +1

    Why prefer hitbox over ray cast ? Thanks for the vid :)

    • @flynsarmy
      @flynsarmy  ปีที่แล้ว +3

      Because it lets you be less precise with your characters orientation.
      A raycast shoots straight forward from the origin. If it misses you'll get no interact prompt. A hitbox means you can just run into the general vicinity of the target and be able to interact with it making gameplay feel a bit less finicky.

    • @ouesh35
      @ouesh35 ปีที่แล้ว

      @@flynsarmy thanks for the answer :)

  • @jordan4longshaw
    @jordan4longshaw 2 หลายเดือนก่อน +1

    Do you have a tutorial on the code that plays the highlight effect? As you didn't open the function for it in the video

    • @mikaelfoster9726
      @mikaelfoster9726 7 วันที่ผ่านมา

      I saw another tutorial by another guy who did something similar, set up an area 3d attatched to the player, if an interactable is within that area, disable its material and switch to the highlight shader, else use default. Im a novice so thats the best i can explain it sorry 😅

    • @mikaelfoster9726
      @mikaelfoster9726 7 วันที่ผ่านมา

      You should be able to find a tutorial or github on how to make a highlight shader material

  • @GaryParkin
    @GaryParkin ปีที่แล้ว

    I have watched a bunch of interactable videos and yours is the best. thank you ever so much. And thank you for the source code so I could see how you did your highlight. It worked perfect.

  • @GaryParkin
    @GaryParkin 8 หลายเดือนก่อน

    I'm revisiting this tutorial and was wondering what is the difference between using the Area3D and using a rayCast3d node?
    In my tests, I added a wall in front of the chest and the character can still open the chest.

    • @flynsarmy
      @flynsarmy  8 หลายเดือนก่อน

      I answered this in an earlier comment. A raycast means you have to look directly at the interactable or you won't get an interact prompt. While playing this can get frustrating especially if the interactable is a small item on the ground.

    • @GaryParkin
      @GaryParkin 8 หลายเดือนก่อน

      @@flynsarmy Thank you. Sorry I missed that. I was more interested in frame rate impact ray cast vs area3d.
      I think I like the area 3d way better for some things.

  • @michaelwalston9486
    @michaelwalston9486 11 หลายเดือนก่อน

    Very nice liked the way you setup the tutorial. One thing I think may break if you go back and click interact a second time you will get an error that its been queue.free(). For this simple example its not a big deal but if someone does not know this could happen will be a bug. I like the door going away from the player in my setup I had created 4 animation for each direction did you uses 1 and change the direction? Use an animation tree? Great stuff would love more advance tutorials lots of things are just simple basic setup stuff. I have found a few other good places that went into like state mach etc... I am also currently working on my first 3d game with my son trying to get him into programming since programming (not games) has been my job for 30 years.

    • @flynsarmy
      @flynsarmy  11 หลายเดือนก่อน

      For the door i got the position of the player relative to the door and rotated it away. It's been a while but I think my example repo linked in the description has a copy if you want to check it out.

  • @kieran1229
    @kieran1229 10 หลายเดือนก่อน

    Hi Flyn, Great video! Quick question. How would I change the orientation of the PlayerInteractor to the way the player faces when using an isometric camera on the main scenea and not one on the player?

    • @kalaris11
      @kalaris11 8 หลายเดือนก่อน

      This may be a late reply -- but Im making a similar game and the way I did it , was move my player interactor to a child of my armature node.. worked flawlessly -- on iso game may have to make that box a bit bigger since you don't have as fine tuned controls like a camera. (I lost 45 minutes realizing my nodes were working but I was missing the interactable due to size)

  • @Fazwooster
    @Fazwooster 5 หลายเดือนก่อน

    Hey! I saw this video and everything is working great! However I am having some issues when my player interactor detects an interactable. It says in the code that I can't call method 'duplicate' on a null value and my game crashes. Is there anything I could do about this? Thank you very much and great vids

    • @flynsarmy
      @flynsarmy  5 หลายเดือนก่อน

      Thanks for the kind words. Try downloading the sample project in the description. It should be working.

  • @Betegfos
    @Betegfos 11 หลายเดือนก่อน

    Awesome stuff, Thanks for the tutorial. I would like to show some text to the player when focusing on an item and also a screen on which a detailed panel of the item would pop up when picked up. How could I achieve that in your opinion? Can I add an export variable to the interactable with a text I want to show to the player?

  • @KonDragon008
    @KonDragon008 ปีที่แล้ว +1

    I've been having loads of trouble trying to make interactable objects, going from tutorial to tutorial; each one having a different method of doing it, and nothing ever working even when I follow it step by step from start to finish (even taking notes).
    With this one, a couple issues came up:
    1. In the "Interactor" script, on line 28 (closest = interactable as Interactable), I keep getting an Invalid cast error which says: Cannot convert from "Area3D" to "Interactable".
    2. When I resize the CollisionShape (UsingPlayerInteractor section of the video), I get Node Configuration Warning that it might not function as expected and needs to be scaled uniformly.
    3. Error "is_open" is not declared in the current scope (the chest node clearly has a script, but we can't see the entire script from this video and there was no mention of it. Since the video title doesn't say "part 2" or something, that means I didn't miss a previous video or anything detailing what that node's script needs to contain for the signals to work)
    Final question is:
    Can the basics of learning the scripting format from this video also help with creating objects the player can pick up (and perhaps put in an inventory) and objects with descriptive text (ie - clicking on an object and it saying something like "This is a box")?

    • @flynsarmy
      @flynsarmy  ปีที่แล้ว +1

      Are you using Godot 4?
      2. Don't use the 'Scale Mode' handles (the little squares) to resize your collision shapes. Use the red circles instead. To fix this go to your collision shape - Transform and reset Scale property to 1/1/1. Then in the 3D viewport look for the red circles on your collision shape. Drag those. That'll change the BoxShape resource size rather than the CollisionShape3D node scale.
      3. The video was meant to show how you connect Interactors and Interactables, it wasn't supposed to be a full demo but I realize that's a mistake on my part, I should have provided a complete demo. I've now done this! Link is in the description.
      Yes, these interaction components can be used for picking up items. Far and away the best inventory system I've found is this one by DevLogLogan th-cam.com/video/V79YabQZC1s/w-d-xo.html

    • @KonDragon008
      @KonDragon008 ปีที่แล้ว +1

      @@flynsarmy Thank you very much! I'll take a look at the full demo as well as the link you provided!

  • @kinda_history_nerd
    @kinda_history_nerd 2 หลายเดือนก่อน

    When I mentioned the controller in the PlayerInteractor script in the following bit of code:
    func _ready() - > void:
    controller = player
    It is giving me an error "Identifier controller not declared in the current scope." Does anybody know why?
    **Note:** I am using ver 4.1.2 stable.

    • @kinda_history_nerd
      @kinda_history_nerd 2 หลายเดือนก่อน

      It fixed itself when I restarted godot

  • @OwenCreery
    @OwenCreery 2 หลายเดือนก่อน

    how did you add the signals

  • @mrhorrorface
    @mrhorrorface 11 หลายเดือนก่อน

    Thanks for the tutorial, although I am having an issue, "invalid get index 'focused' on base 'Nil', I typed the code exactly as shown, any ideas for a fix? I'm using 4.1.2 stable

    • @flynsarmy
      @flynsarmy  11 หลายเดือนก่อน

      Try downloading the demo repo in the description. Should have a working example.

    • @mrhorrorface
      @mrhorrorface 11 หลายเดือนก่อน

      @@flynsarmy Thanks

  • @jilanfk
    @jilanfk 10 หลายเดือนก่อน

    is there anyway to use this in a scenario where the player changes scene when the interactor interacted with the interactable? im really new on this whole godot thing and im trying to make an interactable object where when the interact key is pressed it would change the scene to another scene, thanks

    • @flynsarmy
      @flynsarmy  10 หลายเดือนก่อน

      Of course. You can put any code you want in the interacted signal. How you want to go about changing your scene etc is entirely up to you.

  • @Marces273
    @Marces273 9 หลายเดือนก่อน

    Im using raycast for the crouching, are there any way so that I can interact with the door? Thanks for the vid

  • @kraig800i
    @kraig800i 7 หลายเดือนก่อน

    Did I miss the part where it's explained how to make items glow? ? ? ?

    • @flynsarmy
      @flynsarmy  7 หลายเดือนก่อน +1

      That wasn't relevant to the tutorial so I didn't include it but you can download the example code linked in the description. It might be in there.

  • @rob3625
    @rob3625 ปีที่แล้ว

    i like the style of this interaction system, looks very clean. I am new to the Godot Engine and i cant figure it out, how to pull or push informations from the inherited controller (Player) like a Node3D Position or just a variable. For Example: i am trying to change the position of the interactable to the position of a Node3D Slot i made in my player szene. And if this happens, a bool from my player script should go to true. Any suggestions how i can pull this informations from the controller variable?

    • @flynsarmy
      @flynsarmy  ปีที่แล้ว

      Interactable is passed an Interactor component. In the _on_interactable_interacted function you could do something like interactor.controller.get_node('your_node').global_position

  • @luc0
    @luc0 3 หลายเดือนก่อน

    I found a fix, for those that doesn't detect anything, the Character should be mask 2 and the object layer 2

    • @whoisflu
      @whoisflu 3 หลายเดือนก่อน +1

      your actually such a legend. thanks so much for this fix, game dev is tricky like that sometimes

  • @smartntboy2474
    @smartntboy2474 9 หลายเดือนก่อน

    how do i change it so it can interact with a large group of objects, like the whistle in pikmin kinda thing? i know its to do with the "closest" code but i cant figure out what bit to get rid of, and trial and error is getting me nowhere

    • @rompevuevitos222
      @rompevuevitos222 9 หลายเดือนก่อน

      Use Area3D.get_overlapping_bodies() to get a list of everything the area is touching.
      You can then go trough each object inside with this:
      for node: Node in myArea.get_overlapping_bodies():
      print(node.get_name())

  • @binyot5505
    @binyot5505 11 หลายเดือนก่อน

    Do you have something with raycast instead?

  • @bustlingfungus1412
    @bustlingfungus1412 ปีที่แล้ว

    can't import chest and door from the github repo because it says I'm missing dependencies?

  • @ErikSnider
    @ErikSnider 11 หลายเดือนก่อน

    Could you teach me the reason for using a signal like interactable.interacted.emit(self) instead of calling a function directly, like interactable.interact(self) ?

    • @flynsarmy
      @flynsarmy  11 หลายเดือนก่อน

      You could if you wanted to! Using the signal offers a little more flexibility though as it allows other nodes to connect to the same signal, check for specific interactions and execute code accordingly.
      For example say you have a door that's booby trapped. The door is interactable and will still open fine when interacted with, but the booby trap can be connected to the same component and we want it to trigger as well to damage the player.
      As always though there's no right or wrong way to implement this stuff. Adapt it to suit your needs.

    • @ErikSnider
      @ErikSnider 11 หลายเดือนก่อน

      @@flynsarmy Thanks for the explanation! I watched the video again, and I understand now. The flexibility comes from the ability to attach the signals to a _parent_ of the component, to trigger methods in the parent script. Love it. Still getting used to Godot, and these types of videos help a TON. Thanks for creating this!

    • @ErikSnider
      @ErikSnider 10 หลายเดือนก่อน

      Suppose you want to play an animation on the Player when they open the door, and a different one when they open the chest. Would you handle this in their respective _on_interactable_interacted() methods? Check the type of interactor.controller to verify it's a Player, and then call interactor.controller.play_chest_open_animation(), etc? Is there a better way?

    • @flynsarmy
      @flynsarmy  10 หลายเดือนก่อน

      @@ErikSnider That's probably how I'd do it. It's a bit more tightly coupled than I'd like but I can't think of a better solution off the top of my head.

  • @kenreed1467
    @kenreed1467 ปีที่แล้ว

    Close to what I am trying to do but with left mouse click to interact. First click selects it and on second click on the item or npc and you are not close enough, you move to object and interact occurs

  • @ciaran3244
    @ciaran3244 ปีที่แล้ว

    Got a strange situation where no errors are showing up but nothing from my functions are happening, the door to a scene i have just wont let me interact lol.

    • @flynsarmy
      @flynsarmy  ปีที่แล้ว

      Make sure you have your areas on the correct layer. There's a demo repo in the description of you get stuck.

    • @ciaran3244
      @ciaran3244 ปีที่แล้ว

      @@flynsarmy managed to figure it out, realised it was just a canvas overlay stopping them from working :))

  • @darmawanrendy4481
    @darmawanrendy4481 6 หลายเดือนก่อน

    someone help me to change it to using raycast...

  • @prettycode4028
    @prettycode4028 ปีที่แล้ว +1

    Hello, great tutorial! Apart from the lack of source code to be directly copied. I think it would be a better way of following the tutorial for some people(like me) if there was a github repository from which you could copy stuff. Oh and also you didn't show us the code for highliting and opening. I understand that the tutorial is more about interactions themselvs, but it would benefit people who are doing this kind of a game. Anyways, I really like how clean the system you have here :)

    • @flynsarmy
      @flynsarmy  ปีที่แล้ว +4

      Thanks for the feedback! I've added a demo repo to the description.

  • @truenincillo805
    @truenincillo805 8 หลายเดือนก่อน

    Please version 2d

    • @truenincillo805
      @truenincillo805 8 หลายเดือนก่อน

      Please , version trees,stones,flowers + objects on the ground ,version 2d please

    • @truenincillo805
      @truenincillo805 8 หลายเดือนก่อน

      I need it

  • @Eternal_Night17
    @Eternal_Night17 11 หลายเดือนก่อน

    @onready var chest_material: StandardMaterial3D = chest_meshinstance.mesh.surface_get_material(0) In this code i'm getting a error which says: Invalid get index 'mesh' (on base: 'null instance') does anyone knows how to fix that?

    • @flynsarmy
      @flynsarmy  11 หลายเดือนก่อน

      On the line above where you're defining chest_meshinstance your path must be set wrong.
      Is this in a project you made or my example project on my git repo linked in the description?

    • @Eternal_Night17
      @Eternal_Night17 11 หลายเดือนก่อน

      @@flynsarmy thats in my project and i dont know how to fix it it really freaks me out