[Godot3] How to Click 3D Objects in Godot | Game Dev Tutorial 8

แชร์
ฝัง
  • เผยแพร่เมื่อ 28 ม.ค. 2025

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

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

    This is a much cleaner way of detecting a mouse click than the other method I googled that explained how to make a ray cast from the camera. Thanks!

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

    its insane how the new videos and tutorials are useless,need raycasts and adding some other nodes-classes,connecting them etc.While its this much easy...thank you man saved my hours

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

    I have seen some of your tutorials, and I think you have good knowledge and skills. I hope you are diligently uploading about the Godot 3D tutorial for the Godot community. thank you!

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

    Wow this is awesome, all the videos that you created are so useful, I'm sure your channel will have a large audience, thanks estimated Dave

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

    This is great just what I was looking for.

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

    Followed the video and nothing happened. Is this broken in 3.5

  • @Obsidian-Tux
    @Obsidian-Tux 4 ปีที่แล้ว +1

    Thanks, this helped me a lot :)

  • @miguelsarmiento9268
    @miguelsarmiento9268 4 ปีที่แล้ว

    click in 3d very good only you explain this thanks for the help

  • @hoppalapasam53
    @hoppalapasam53 3 ปีที่แล้ว

    thank you so much, this is realy help me out. but i did use it with touch screen input touch. its work that way as well.

  • @aleksandersanya1817
    @aleksandersanya1817 2 ปีที่แล้ว

    Very helpful! Thanks.

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

    This is fantastic, very simple, but it seems to allow me to click on objects which are hidden behind other objects in the scene, I don't know if I've missed a step but how do I stop hidden objects being clickable?

  • @Retales
    @Retales 4 หลายเดือนก่อน

    I had already started working on something way more complicated and beyond my skill level, because I thought I could maybe handle it. Luckily I googled a bit more and found this

  • @mikorsky_s.92
    @mikorsky_s.92 หลายเดือนก่อน

    Yo thanks man!

  • @Galaxy-pm2ff
    @Galaxy-pm2ff 4 ปีที่แล้ว

    sorry, how do I make the button with mouse mode captured on?
    nice tutorial by the way

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

    Great video! But why there are 2 mouse cursons at 1:09?

    • @DavetheDev
      @DavetheDev  5 ปีที่แล้ว +5

      lol nice eyes. Sometimes when I'm editing the videos, there is too much to say and not enough video, so I take a screenshot of the video to pause it while explaining something. During the screenshot, sometimes my mouse gets in the way. So, there is the mouse on the video and the mouse when I take a screenshot. Now that someone has noticed, I'll either find a better way to pause the video, or.....just have everyone play Where's Waldo with mouse cursors....hahhaah

    • @Hajdew
      @Hajdew 5 ปีที่แล้ว

      @@DavetheDev i know in sony vegas is a screen shot option but idk which software do you use.Also im a big fan of yours intro's

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

      @@Hajdew I use Blender for video editing. I learned if you press F12, blender will render the current frame as an image that can be imported back into the video editor. Thanks to you, I learned something new. :) As for the intro, I used to do a lot of programming on the TI-83+ calculator when I was a kid, so what you're seeing is a TI program running on an emulator, glad you like it.

    • @moric4677
      @moric4677 5 ปีที่แล้ว

      that's illuminati

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

    I have input ray pickable on and I cant make the on input event work at all

  • @joaofaleiro8297
    @joaofaleiro8297 4 ปีที่แล้ว

    Thank you so much dude

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

    Nothing happened, is it different in Godot 4? I assume so since for example the ray bool was already enabled

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

      Yes, it was made for Godot 3. Thanks for the feedback. I've changed the title of the video to reflect that it only works in Godot3.

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

    Sorry to ask something that might be unrelated, but I don't know how to solve this:
    I have a 2d scene, which has a Viewport in it to show a 3d object in this scene. Now, if I understand correctly, there is no way to actually make that object clickable using Viewport, because, basically, I use the Viewport to get texture from this object. Maybe there is actually a way to make the texture clickable, but I don't know about it. Do you mind sharing the solution if there is one?

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

      Off the top of my head, use a TextureRec to display the texture from the Viewport. When you click the TextureRec, you'll get an InputEvent for via the "gui_event" signal. Take that event and manually translate it into a new event that will be picked up by the 3D Area node of your 3D object. You can fire fake events down the node tree by via the SceneTree. So, in psudocode it would be this...
      1. Capture the click event postion on the TextureRec.
      2. Translate the click position from the TextureRec coords into the 3D camera's screen-space coords.
      3. Make a new instance of an InputEvent and put the screen-space coords in its properties.
      4. Fire the custom "fake" InputEvent down the NodeTree via the SceneTree.
      5. Pickup the InputEvent in the 3D object's Area node like normal via it's InputEvent signals as shown in the video.
      I haven't done it myself, but I'd be curious to learn how it goes...

    • @kedalovo
      @kedalovo 4 ปีที่แล้ว

      @@DavetheDev Thank you very much for the answer! I will try this some time soon and return in any case (success/failure). Just started learning Godot like 2 days ago, so this is unbelievably helpful

    • @kedalovo
      @kedalovo 4 ปีที่แล้ว

      @@DavetheDev OK, I got stuck on the second step (a bit further than I thought). I successfully understood how to get the position of click, but have no idea how to get these coordinates go to function inside my 3D scene. Tried to call that function from the main scene inserting click_position, but got so many mistakes that I don't think I am doing anything correctly. Sorry for taking your time, but if you could spare some, would you mind explaining it a bit more down-to-earth?

    • @DavetheDev
      @DavetheDev  4 ปีที่แล้ว

      @@kedalovo Explaining is a bit complicated, but it's an interesting problem, so I made an example demo instead. Download and Setup this Godot project: github.com/EXPWorlds/Godot-Tutorials
      Under the "8 Clicking 3D Objects" folder is a Supplementary folder and another folder with your youtube user name. Load the "Demo" scene and run it with F6.
      Hope that helps better than my rambling explanations. ^_^ Let me know how things go.

    • @kedalovo
      @kedalovo 4 ปีที่แล้ว

      @@DavetheDev Thank you very much, I'm amazed by the fact you are still willing to help me. I hope that what you have already given is enough to figure things out by myself.

  • @gd7681
    @gd7681 4 ปีที่แล้ว

    Thanks for the tutorial. What is the purpose of creating the Sphere Spatial node instead of just creating the Sphere meshinstance directly?

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

      Good question. You can use the MeshInstance directly if you want. By habit I create things using a principle called "Separation of concerns" en.wikipedia.org/wiki/Separation_of_concerns In which each object has a specific job. In this case, the Spatial Node's job is to encapsulate an "entity" in the game world, and the job of the MeshInstance is only to display what the entity looks like. In simple examples like this, it doesn't much matter, but as things get more complex, Separation of Concerns becomes really important. I didn't really think about all that when I made this though, like I said, it was mostly because of habit.

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

    Thank you

  • @ivanaksmsk
    @ivanaksmsk 3 ปีที่แล้ว

    Thank you!

  • @iamlordstarbuilder5595
    @iamlordstarbuilder5595 2 ปีที่แล้ว

    Any idea how to detect whether it is clicking away? Would be nice to deselect something in the same way I selected it.

    • @DavetheDev
      @DavetheDev  2 ปีที่แล้ว

      Can do. When you select something add it to a list of selected things. When you click again anywhere on the screen, iterate through the list of selected things, deselect them and remove them from the list before checking if something new was selected.

    • @iamlordstarbuilder5595
      @iamlordstarbuilder5595 2 ปีที่แล้ว

      @@DavetheDev I actually went with something different, I added a boolean that the selected object flips when clicked and then the next frame is flipped back off, only way to turn it on again is to select an object. Your solution works for multiple objects ig, but I’m only selecting one at a time in my game

    • @DavetheDev
      @DavetheDev  2 ปีที่แล้ว

      @@iamlordstarbuilder5595 Sweet!

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

    Damn. Thanks.

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

    Thank you :D

  • @logangraham2956
    @logangraham2956 4 ปีที่แล้ว

    i am having a bit of an issue clicking these area nodes through my players hud ,
    if i turn off my huds visibility i can click the area nodes
    but if the hud is visible then i am not able to click the area nodes.
    how do i get my clicks to go through my hud?
    its a control node

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

      In the Inspector, Control derived nodes have a "Mouse" menu. Under that menu there is a "filter" drop down with the options, "Stop, Pass, Ignore". Try changing those filter options.

    • @logangraham2956
      @logangraham2956 4 ปีที่แล้ว

      @@DavetheDev i actually tried that setting once and thought it was useless XD
      i set it to pass and it did nothing.
      i tried ignore this time and it worked.
      that so weird , I'd think that "pass" = "pass-through".

    • @DavetheDev
      @DavetheDev  4 ปีที่แล้ว

      @@logangraham2956 Yeah, it can be a bit misleading. Glad you got it to work. The "pass" option actually captures mouse input, but if the control node that was clicked doesn't handle the input it will Pass the event along to a parent control node, if there is one. At least that's what the documentations says...

    • @logangraham2956
      @logangraham2956 4 ปีที่แล้ว

      @@DavetheDev my next challenge is getting proper camera rotation and then maybe figuring out procedural generation for infinite ground
      my current solution is to exported a vector3 which i set to equal my velocity and then i just move the ground on the x+z so it always stays under the player.
      its a temp fix but it'll hold till i figure out how to generate ground from code instead of manually placing every single block.

  • @kohrakvaza
    @kohrakvaza 4 ปีที่แล้ว

    Thanks for the tutorial.
    Trying the demo, it seems like the spheres all change color when clicking one of them, instead of changing individually.

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

      That's because all three of your spheres probably share the same material. Right click on the material and select "Make Unique". When you duplicate things in Godot, the duplicates share any sub-resources like textures, shaders, materials, curves, etc. unless told not to.

  • @mirohorvath
    @mirohorvath 5 ปีที่แล้ว

    thank you

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

    Hi, is any one know how to call this type of functions from C#?

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

      using Godot;
      using System;
      public class YourClassName : Node3D
      {
      public override void _Input(InputEvent @event)
      {
      if (@event is InputEventMouseButton mouseButtonEvent)
      {
      if (mouseButtonEvent.ButtonIndex == (int)ButtonList.Left && mouseButtonEvent.Pressed)
      {
      GD.Print("Pressed Left Mouse Button");
      }
      }
      }
      }
      Try this.

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

    Funciona para juegos en Android?

  • @kishonoi191
    @kishonoi191 3 ปีที่แล้ว

    what about with a crosshair?

  • @davy-cx3vu
    @davy-cx3vu 4 ปีที่แล้ว

    Thanks

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

    strange that this signal wouldn't include a reference to the node that was just clicked on.
    i have the Area3D send a signal to my camera and i want to detect which object i last clicked on to make the camera orbit around that object.

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

      That's what I'm trying to do as well, did you find any solution to get the node just clicked?

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

      nvm, just found a solution, the argument "shape_idx" return the index of the collision shape of the area, but since there's only one collision shape, it will always return 0.
      So the best thing to do is to use a single Area3D and adding all the CollisionShape3D as children, as many as you want; this also mean that the Mesh must be child of the CollisionShape

  • @christianbatista0
    @christianbatista0 2 ปีที่แล้ว

    FU thx so much