Raycasting in Godot - The Engine Feature Every 3D Game Uses

Поділитися
Вставка
  • Опубліковано 25 січ 2025

КОМЕНТАРІ • 62

  • @Mixthelightintogray
    @Mixthelightintogray 3 роки тому +33

    even I already knew about raycast, I just clicked on the video because of: "oh, another Godot chanel?"
    The quality, the good explanation and Nujabes in the background made me raycast my gaze into the subscribe button and collide with the mouse.

  • @leirex_1
    @leirex_1 Рік тому +17

    Before anyone copies the code into their Godot 4 project:
    Godot 4 changed the way you have to set up your ray intersection. intersect_ray doesn't take and anymore, it now takes a PhysicsRayQueryParameters3D. I suggest reading the Documentation for more info.

  • @tom_paul_3d
    @tom_paul_3d 3 роки тому +44

    Phenominal tutorial, you've earned a subscription

  • @besimist8604
    @besimist8604 3 роки тому +11

    even though i already know what raycast is, your video so smooth that i can't stop to watch it

  • @blhtml
    @blhtml 3 роки тому +2

    WOW I go into this UA-cam with ZERO expectation!
    It' one of the best GODOT UA-cam video in a very long time
    I need to rewrite my tab target system now

    • @therealwhite
      @therealwhite 8 місяців тому

      You raykissed the button!

  • @DavidRycan
    @DavidRycan 8 місяців тому

    Spent an hour trying to figure out how to set up Raycasting, only to find this channel and have every question answered concisely and simply. Thank youuuuuuuuu and also I love your animations they're adorableeeeeeeeee

  • @Failfer
    @Failfer Рік тому +1

    This is amazingly made what the heck, good job and amazing work

  • @renanstn7659
    @renanstn7659 3 роки тому +6

    What a wonderful video!
    Love the explanations and the animations.
    Thank you!

  • @stevedowning3892
    @stevedowning3892 Рік тому +1

    Gorgeous visuals and a great tutorial, time to put this into practice!

  • @bibubobee6130
    @bibubobee6130 3 роки тому +3

    I've been trying to find out how to use the Raycast in a more dynamic way, you've just saved me a lot of frustration with that explanation about intersect_ray

  • @names_garlic
    @names_garlic 4 місяці тому +2

    4:35 That indentation is CRIMINAL 💀

  • @thedupy124
    @thedupy124 3 роки тому +5

    Excellent explanations, amazing animation, all crystal clear, amazing video

  • @dustinthompson8600
    @dustinthompson8600 3 роки тому +3

    Love your channel. These videos are great for the Godot community.

  • @theARDISAN
    @theARDISAN Рік тому

    Love the way to edit your videos. It's very visually pleasing.

  • @SkyIsTumbling
    @SkyIsTumbling 3 роки тому +2

    game dev + nujabes, good shit man i just subbed

  • @snesmocha
    @snesmocha 3 роки тому +2

    This is extremely informative, subscribing

  • @yosuanicolaus
    @yosuanicolaus 3 роки тому +1

    Woah man, this tutorial is frickin good! Subscribed

  • @rayuserp
    @rayuserp 3 роки тому +1

    nice short and easy to understand tutorial amazing work keep it up

  • @realMenta
    @realMenta 2 роки тому +1

    The pistol trigger is on the wrong side at 1:13. Good video!

  • @michaelhawkingphd
    @michaelhawkingphd Рік тому +1

    I believe this tutorial is out of date. You now have to do something like this:
    var query = PhysicsRayQueryParameters3D.create(position, position + Vector3(0, -10, 0))
    var collision = get_world_3d().direct_space_state.intersect_ray(query)

  • @Reneator
    @Reneator 3 роки тому +1

    Great and insightful video! Keep it up!

  • @mjdevlog
    @mjdevlog Рік тому

    Juat found this channel via this video. You did an amazing way visualizing it.

  • @jdigi78
    @jdigi78 Рік тому +6

    FYI, mario galaxy doesn't use raycasting for the gravity at all. It uses gravity volumes that have different "shapes" like a sphere, disc, or cylinder

  • @joederksen7441
    @joederksen7441 3 місяці тому

    thumbs up for choosing nujabes as backgound music :)

  • @javgroman
    @javgroman Рік тому

    Very helpful summary, thank you for the vid!

  • @guyabikhair7066
    @guyabikhair7066 2 роки тому

    Really handy video, thanks for making it! :)

  • @SconeysASMR
    @SconeysASMR 3 роки тому

    Huh this video has amazing styled visuals

  • @adrinuk_gamedev
    @adrinuk_gamedev 3 роки тому

    A really good video, with stunning animation, thank you for teaching me something today :,) New sub

  • @dekingking315
    @dekingking315 2 роки тому

    liked and subscribed, also you have an amazing voice

  • @Daviesdev
    @Daviesdev 2 роки тому

    Good stuff man 🙌
    I wish I could make my tutorials this good
    Definitely subbed

  • @prolific_joker5065
    @prolific_joker5065 3 роки тому

    very high quality video :D

  • @ThaMentalGod2003
    @ThaMentalGod2003 2 роки тому +2

    music in the background: Nujabes - Aurarian Dance (if anyone's interested) 😎great song, i love nujabes and j dee

  • @jugibur2117
    @jugibur2117 Рік тому

    Very helpful, thanks!

  • @mo3dev
    @mo3dev 2 місяці тому

    This is great!

  • @felfar197
    @felfar197 7 місяців тому

    such a nice video :) ♡♡♡

  • @benjaminjsinger
    @benjaminjsinger 3 роки тому +2

    Great video! 2 questions:
    1. How would I take advantage of the intersect_ray() method when I don't know the endpoint of my ray, but know the direction my player is looking and the distance of the ray?
    2. How would you accomplish the feature of bullet drop using godot's raycasts?

    • @Pefeper
      @Pefeper  3 роки тому +2

      1. If you have the direction your player is facing as a normalized vector, you can multiply that by the distance, then in intersect ray you would make the end point the origin + that multiplied vector.
      2. This one is a bit tricky, and raycasts might not be the solution. It would be worth diving more into it online, I'm sure there's dozens of techniques I have no idea about. My off the cuff idea would be to create a projectile as it's own entity that travels at a high speed, but moves multiple times in a single physics frame (to avoid cases where it moves too quickly to intersect anything). You could make it move in anyway you wanted, gravity, wind movement, etc. Just use a method like overlap sphere every time it moves to see if it hit anything.
      Hopefully that helps!

    • @evannibbe9375
      @evannibbe9375 2 роки тому +1

      @@Pefeper Another way to do a bullet if you know what the drop will be is to just use blender to make a long cylinder parabola with some small volume.
      Then export this as a .obj, then put it in your Imports folder in your Godot project. Then create an Area node, add a MeshInstance to it, in the inspector of the Mesh, load the .obj. Then click the top middle button saying “Mesh”, then Make Convex Collision Siblings. Then go over to the node panel to turn visible “off” on the MeshInstance.
      You can then use the area shape to detect if anything has crossed into its space, which means it was hit with a bullet if a bullet has been fired.

  • @falfit.
    @falfit. 8 місяців тому

    How can i get a collision on the exit of a collider? Im trying to make accurate bullet penetration but i need to know when does the raycast leaves the collider that it first hit. So i thought relaunching a raycast at the collision point of the collider, just a bit inside it, in the same direction, but i cant make it detect when it leaves the collider? It seems it only detect entering a collider. How can i make it consider exiting a collider as a collision?

  • @kieunghiaduong4848
    @kieunghiaduong4848 9 місяців тому

    Is there a way to make the jump higher the longer you hold the key in godot, similar to the game Jump King?

  • @Lucas-gg9yb
    @Lucas-gg9yb 3 роки тому

    is one of these methods more performant than other?
    best tutorial with this theme on youtube btw!

    • @Pefeper
      @Pefeper  3 роки тому +1

      Thanks! I think performance differences between the two are pretty minor, with the slight edge going to the physics server. Of course, it really depends on the use case. If you want to do 100 raycasts every frame, you would see better performance using the server than 100 raycast nodes for sure. But if it's just one raycast per frame? The convenience of the raycast node might be worth the inconsequential performance hit.

  • @eliyahumedia
    @eliyahumedia Рік тому

    How would you use raycasting with decals to make trailing footprints for a character controller?

    • @Pefeper
      @Pefeper  Рік тому +2

      I would use a function that can raycast down from some point just above the point at which the foot hits the ground. If that raycast collides with anything, spawn a footprint decal at the collision point, and rotate it so it matches the foot's orientation. You can optionally use the collision normal to also align the decal's up direction to the surface of the geometry, but that would only be necessary under certain circumstances. Finally, I would call this function from within your animation player, so it can accurately sync with the moment the foot touches the ground.

  • @RafaFiedo
    @RafaFiedo 3 роки тому +1

    Nice!

  • @octagear
    @octagear 2 роки тому

    Gosh, in Godot 4 changes have been made to how you reference the physics server and how you query a raycast with it o.o

    • @Pefeper
      @Pefeper  2 роки тому

      yeah Godot 4 has changed a lot of stuff! Since the beta is out now, I might go back and make an updated version of this video

  • @joshelguapo5563
    @joshelguapo5563 Рік тому

    Is that Samurai Shamploo music?

  • @estagiarioyt
    @estagiarioyt Рік тому

    What program do you use to make the animations?

    • @Pefeper
      @Pefeper  Рік тому

      For this video, I just used the grease pencil feature in Blender. It's pretty great!

  • @kraig800i
    @kraig800i 10 місяців тому

    I recently got a code working that allows me to mark certain items as interactable and it can initiate actions on sight, when out of sight and when clicked on. This is a big step forward for me personally.
    I was thinking can I use the same code that allows the same objects to be identified/interacted with to draw the torch to them? I set up a raycast_3d and attached it to the torch like a lance. I'm thinking there has to be a way for it to point to the closest interactable object and by extension pointing the torch to said object.
    Does this sound plausible or am I going in the wrong direction?
    After watching this video I'm wondering if I should perhaps use the server option and have it point to the closest item that is both insider of a collider box and with in a set distance of the player. How that actually can be coded is currently a mistery to me.

    • @Pefeper
      @Pefeper  10 місяців тому +1

      Maybe I misunderstood your intention, but I don't think you'd need to use raycasts at all for this. You should be able to iterate over every interactable object in the scene (in a for loop) and find the closest one to the player by using the players position and the objects position. Then the direction to point the torch in would just be Normalize(nearest_object.position - player.position)

    • @kraig800i
      @kraig800i 10 місяців тому

      @@Pefeper The interactor script I got from this video... It uses signals and three seperate scripts to identify a interactor, interactable and when the object has been interacted with via the three seperate signal nodes from the player. I want to make a game that has some clutter in some of the rooms. It's hopefully going to have some old school puzzles like SH1 and RE1 but in a first person format. In those two games the character would turn their head subtly towards any itmes of interest found in the room.
      I was thinking it might be interesting to have a simillar dynamic in first person, however it takes the flash light away from the centre of the screen and focuses it on interactable items whenever their on screen.
      ua-cam.com/video/gTpteB2kRUc/v-deo.html

  • @baratao5000
    @baratao5000 Рік тому

    Very cool

  • @chuckles1252
    @chuckles1252 2 роки тому +2

    That Nujabes tho

  • @wolcamophone4783
    @wolcamophone4783 3 роки тому

    I used this to make an FPS controller stay crouched when crawling under something, so they don't expand again and start jittering while in a vent. Edges can still get snagged tho since I'm using a cylinder colider instead of a capsule. Any suggestions to help it not get clipped? I feel like I could add a single cylinder base for the player's feet so they don't slide off getting too close to edges due to the capsule's slope, but that would probably just make the player scene more complicated than it needs to be.

  • @doodoo-ui2lt
    @doodoo-ui2lt Рік тому

    TYSM BRO ILYI GAVE A SUB AND LIKE

  • @skulltrick
    @skulltrick 3 роки тому

    Very informative for Godot 3.4 and below, but this method no longer works in Godot 4.0 +
    The intersect_ray method only takes 1 argument now and the documentation isn't very helpful (for me at least)

    • @Pefeper
      @Pefeper  3 роки тому

      I haven't gotten the chance to look at the alpha yet, so I can't speak from experience on Godot 4 yet. However, from the docs, it looks like it uses a new PhysicsRayQueryParameters3D object, which stores all the raycasting information (like the raycast origin and end point)

  • @danielthompson8993
    @danielthompson8993 3 місяці тому

    Like for Nujabes