Godot 4 3D Mouse Tutorial

Sdílet
Vložit
  • čas přidán 3. 11. 2023
  • Quick tutorial on how to click in 3d space in Godot 4!
    #godotengine #godottutorial #tutorial #coding #gamedevelopmenttutorial
  • Věda a technologie

Komentáře • 35

  • @b-radster9148
    @b-radster9148 Před 4 dny +1

    Idk if there is anyone from the future looking at this, but if you are getting an error with the project_ray_origin() and project_ray_normal() its because you have to execute these on your camera, so the code could be (After creating a var called camera and setting it equal to your camera node) camera.project_ray_normal() or the other function, fixed my issues!

  • @dieloei
    @dieloei Před 5 měsíci +13

    Thank you. This is to the point and I got what I want. I have one suggestions though - instead of just reading what you're typing when you code, explain a little more about what it is that you are doing. Some basic explanation of project_ray_origin, project_ray_normal, direct_space_state, etc. would add a lot of value to this video.

  • @MrTom911pl
    @MrTom911pl Před 5 měsíci +18

    nobody asked but here is code(2:34):
    func _input(event):
    if event.is_action_pressed("click"):
    shoot_ray()
    func shoot_ray():
    var mouse_pos = get_viewport().get_mouse_position()
    var ray_lenght = 1000
    var from = project_ray_origin(mouse_pos)
    var to = from + project_ray_normal(mouse_pos) * ray_lenght
    var space = get_world_3d().direct_space_state
    var ray_query = PhysicsRayQueryParameters3D.new()
    ray_query.from = from
    ray_query.to = to
    var raycast_results = space.intersect_ray(ray_query)
    print(raycast_results)

  • @Hector_Creates
    @Hector_Creates Před 29 dny

    Single greatest godot tutorial ever made, and I've watched hundreds. Please keep doing this.

  • @njdarda
    @njdarda Před 7 měsíci +4

    i love how to the point your tutorials are

  • @jasonwilliams8730
    @jasonwilliams8730 Před 9 měsíci

    Great tutorial as always, thank you!

  • @Mothman13
    @Mothman13 Před 3 měsíci

    Thank you, this helped me figure out exactly what I needed to know.

  • @DavidArt
    @DavidArt Před měsícem

    perfect .. Thanks

  • @jusikskirata9700
    @jusikskirata9700 Před měsícem

    This is huge, thanks!
    However, it really made me laugh. I've got my camera on a rig, as it was the easiest way for me to make it rotate around my world. Now however, the red spheres stay fixed to my camera. I'll try to figure this out, but you helped so much!

  • @bjornstrandberg8146
    @bjornstrandberg8146 Před 6 měsíci

    i made it. thank you. i used the @export var target_location:Node3D instead and dragged in a marker object to direct my navmesh units units

  • @owenlloyd2528
    @owenlloyd2528 Před 9 měsíci +1

    Thanks

  • @Zozo_uwu_
    @Zozo_uwu_ Před 2 měsíci

    This is like the closest i can find to what i need 😿. I have a cam that follows my character in the middle of the screen and i want a flash light to spin around the character pointing at my mouse. nothing i can find for godot 4 tells me how to do this

  • @reishomaru
    @reishomaru Před 3 měsíci

    I hope you are still here.. please guide. I want the object with wich im interact to call another function, i.e. print dialogue. I figured out how to do it with a signal on input_event, but can't understand how do it manually on raycast as in your example.

  • @DuhKoreGames
    @DuhKoreGames Před 21 dnem

    is there any way to add exceptions? like in a traditional raycast3D node

  • @ForgottenMovieGems
    @ForgottenMovieGems Před 20 dny

    I have a problem.
    The raycast result is empty even when it should be hitting my CollisionShapes in my scene.
    Any idea why this might be happening? I've checked both masks and layers and they are at their default where only the 1st layer on both layer and mask is highlighted.
    I'm getting desperate here. Any help would be SUPER appreciated

  • @da_roachdogjr
    @da_roachdogjr Před 9 měsíci +1

    How do you figure out all those methods? (talking about in general)
    Searching the online manual is always so clunky.
    Good video as always. 👍

    • @Gwizz1027
      @Gwizz1027  Před 9 měsíci +2

      Google, Godot forums, and mainly Godot Documentation

  • @TheMikeMassengale
    @TheMikeMassengale Před měsícem

    Maybe someone here will be able to answer this question:
    The whole tutorial went fine for me, but when I try and summon the balls on click, I can't seem to get them to spawn in, is there a way I can somehow check that it's being summoned and not falling through my floor or something?

    • @Gwizz1027
      @Gwizz1027  Před měsícem

      If they aren't rigidbodies they can't fall through the floor

  • @Myth_Maker_Forreal
    @Myth_Maker_Forreal Před 6 měsíci

    hey is there a way to make an object that is already in the scene move to the point you click on instead of making a new thing spawn on the location just curious??

    • @lankdastudio
      @lankdastudio Před 5 měsíci +1

      Instead of the three lines inside the 'if' write (where Node is the object you want to move): Node.position = raycast_result['position]

  • @Gostyr
    @Gostyr Před 6 měsíci +1

    Invalid call. Nonexistent function 'instantiate' in base 'String'.
    this thing is on func's shoot_ray, and _input please help. i did the alternative free project and same nodes as you, made node with mesh in another tab same as you, but steel getting this stupid error

    • @Myth_Maker_Forreal
      @Myth_Maker_Forreal Před 6 měsíci

      me too I have the same problem and can't find a solution can someone please help

    • @Myth_Maker_Forreal
      @Myth_Maker_Forreal Před 6 měsíci

      found the solution to our problem firs make sure that var ball is written like this: var ball = preload("res://ball.tscn")
      then the other section is written like this:
      if not raycast_result.is_empty():
      var instance = ball.instantiate()
      instance["position"] = raycast_result["position"]
      $'../'.add_child(instance)
      and it works for me so I hope this helps you

  • @yuqianglin2517
    @yuqianglin2517 Před 3 měsíci

    Thanks a lot. The tutorial is clear and simple.

  • @Zuki_the_cat
    @Zuki_the_cat Před 9 měsíci

    plz make blender tutorial

  • @Kagekao_666
    @Kagekao_666 Před 9 měsíci +1

    спасибо братан!

  • @lugas4270
    @lugas4270 Před 5 měsíci

    Really great tutorial, get most of the work done. Is there any downside to this method? since my object position is not really accurate in the y-axis? I print the raycast_result.position and apparently, the y-axis is constantly at 0.5.
    edit: never mind, I got a box collision in front of me 😂😂. Thanks for the tutorial!

  • @ElepIn
    @ElepIn Před 9 měsíci +2

    First

  • @qingyun6005
    @qingyun6005 Před 9 měsíci +1

    I don't understand. I don't know the principle, haha..

    • @Gwizz1027
      @Gwizz1027  Před 9 měsíci

      you're shooting a ray from the camera, to the point on the mesh

  • @tiktokdailyreview7015
    @tiktokdailyreview7015 Před 8 měsíci +1

    what about orbit around an object, I have a hacky way which does no work well ...if you have an idea you can help