No video

Ray-casting from the screen : Look at the mouse in 3D [GODOT]

  Рет қаралды 29,444

Nolkaloid

Nolkaloid

Күн бұрын

Quick video explaining how does ray-casting from the screen works and how to use it in your games, to make a character look at the mouse position.

Пікірлер: 83
@rhevoramirez7969
@rhevoramirez7969 Жыл бұрын
Note: in Godot 4 its necessary to construct the query to call as argument for the intersection: var query = PhysicsRayQueryParameters3D.create(RayOrigin, RayEnd); var Intersection = SpaceState.intersect_ray(query), otherwise itwill not work ;)
@TheCrazyGetawayGuys
@TheCrazyGetawayGuys Жыл бұрын
god bless your soul
@matthewdavenport1335
@matthewdavenport1335 Жыл бұрын
You saved my life!
@mertgulec7541
@mertgulec7541 11 ай бұрын
thanks a lot dude I'd be bald by now if I had not seen this
@Gab_van_YouTube
@Gab_van_YouTube 10 ай бұрын
It doesn't work
@kaduyeah
@kaduyeah 8 ай бұрын
You sir deserve a crown
@davidmurphy563
@davidmurphy563 3 жыл бұрын
I was doing this exact same thing and found your tutorial just after my computer bluescreened to tell me to go to bed. :) I didn't know that camera had project ray normal. That's ideal. I was expecting to use the UV coords of the camera and its origin and try to do it manually, this is much better. Thanks buddy.
@arkadiyviking3919
@arkadiyviking3919 3 жыл бұрын
A collision object in the Godot has a function: _on_StaticBody_input_event(camera, event, click_position, click_normal, shape_idx).
@psuw
@psuw 4 жыл бұрын
Wow. Stunning well explained! Keep that good stuff up pls!!!
@Nolkaloid
@Nolkaloid 4 жыл бұрын
Thanks!^^
@Developers_den
@Developers_den Жыл бұрын
thank you very much i was very tired of using diffrent methods and my brain eas going to explode you saved my life you are the best
@ajpink5880
@ajpink5880 Жыл бұрын
thank you! you just made my project very nice and simple :) and the explanation was fantastic.
@JonathanDevine
@JonathanDevine 4 жыл бұрын
This was incredibly helpful. Thank you! Looking forward to the next video.
@misterartyparty
@misterartyparty 3 жыл бұрын
Yup, that was better that Godot docs, thanks a lot !
@First_Lst
@First_Lst Жыл бұрын
What a great explanation. Great job.
@ahjed7397
@ahjed7397 4 жыл бұрын
Pls continue making random godot tut. Ur vids on point.
@Nolkaloid
@Nolkaloid 4 жыл бұрын
Thanks! I don't have much time and motivation right now, but I'm not planning to go anywhere :)
@ahjed7397
@ahjed7397 4 жыл бұрын
@@Nolkaloid ya, i know making vids need time and efforts. About motivation Godot in couple of years will be something. If u have atleast good enough tuts u also will be something, and ur tutorials have good quality honstly.
@Nolkaloid
@Nolkaloid 4 жыл бұрын
Thanks man, appreciate it.
@greg7987
@greg7987 4 жыл бұрын
Great great tutorial! Much thanks to you.
@YourGalaxyInc
@YourGalaxyInc 4 жыл бұрын
Amazing, i helped me a lot. Thanks, good work mate.
@VroniastyGamingHD
@VroniastyGamingHD 3 жыл бұрын
Very good tutorial, helped me a lot
@michkrauss
@michkrauss 2 жыл бұрын
Nice Tutorial - works fine but is there a way to make the camera only follow on x and y axis ?
@thekingbenjy
@thekingbenjy 2 жыл бұрын
instead of "Vector3(pos.x, 0, pos.z)" do "Vector3(pos.x, pos.y, 0)"
@ArtembAartemb
@ArtembAartemb 2 жыл бұрын
Thank you, thank you, THANK YOU!
@nvm9174
@nvm9174 Ай бұрын
thank you so much
@ralfbierig
@ralfbierig Жыл бұрын
Nice video. What application you use to make these animations?
@TheHauntedSockdrawer
@TheHauntedSockdrawer 4 жыл бұрын
awesome tutorial. subbed
@MadheadStardust
@MadheadStardust 2 жыл бұрын
It doesn't work for some reason. I did everything correct, I think. What do you have when you open RIG up. I was wondering if I need to write the code above the process_function(delta) line? thanks for the video, I just wished I could get the object to move with the mouse.
@Nolkaloid
@Nolkaloid 2 жыл бұрын
Hi, could you explain the issue in detail. I don't quite get what's your problem.
@MadheadStardust
@MadheadStardust 2 жыл бұрын
@@Nolkaloid I don't know. For some reason the script didn't work. It would not control the mesh. I started the script after Physics_Process(Delta) but I noticed there was some script above it, should I include that as well, speed and velocity extend. Also your RiG spacial mode had an arrow showing that there were other things attached to it. I tried everything, but I am new to programming in general. It won't rotate the node at all. It seems everyone else figured it out so I must be missing something. Thanks for the video it was still helpful, I appreciate your help anyway.
@Zyiah
@Zyiah Жыл бұрын
Thank you lad!
@lorenzfk8432
@lorenzfk8432 3 жыл бұрын
you're a hero
@R250Tv
@R250Tv 9 ай бұрын
Hi! I don't know why but my character faces the opposite way from the mouse, does anyone know how to fix this?
@yungson7869
@yungson7869 2 жыл бұрын
I understand why you pass in the translation.y to the look_at function (to convert the raycast to a straight line). But why does my rig appear to point at a position above it rather than at the same height?
@Nolkaloid
@Nolkaloid 2 жыл бұрын
Probably something to do with world / local space. Try "Transform.origin.y. "
@pand2aren
@pand2aren 4 жыл бұрын
hi thanks, it really helped to understand how to use raycast from camera, and look_at, have a question as im a beginner in programming in general, im thinking that i can use this raycast from camera to position characters cross-hair/cursor on ground, and make it follow mouse position. Im just stuck on "concept" how to implement it, i have interpolated camera, player node as a scene with childnode "Positiond3d" its target for interpolated camera to follow, crosshair node spatial, Should i raycast from Camera via script, and use own scripts for player node and crosshair node to change position(crosshair) and look at(player) ? im stuck accessing from player node, ray collision position. Maybe theres a better way ? Anyway thanks for videotutorial!
@Nolkaloid
@Nolkaloid 4 жыл бұрын
Hello! I'm not quite sure what you mean... Could you upload a video maybe?
@moric4677
@moric4677 Жыл бұрын
space_state.intersect_ray(origin,end) showing error in godot 4 alpha , it says that function expects 1 argument
@Aprch
@Aprch Жыл бұрын
You need to provide a PhysicsRayQueryParameters3D object. It's basically the same, just wrapped in an object. Check the manual!
@jenek0767
@jenek0767 3 жыл бұрын
очень помог этот гайд. спасибо
@regularguy3879
@regularguy3879 3 жыл бұрын
whenever i point the cursor at any other mesh in my viewport, including character mesh, my character still "leans" towards it, setting the look_at argument does not work for me, any ideas ?
@Nolkaloid
@Nolkaloid 3 жыл бұрын
Could you provide a code snippet?
@eray3681
@eray3681 2 жыл бұрын
You probably import the character from blender. In blender, -z is down but in godot its forward. So when you import the character, its comes with x 90 degree since its needs to look "forward" not "down". Deleting the "traslation.y" part from the look_at function and rewriting big numbers such as 2000 kinda fixes it.
@txvi4648
@txvi4648 2 жыл бұрын
@@eray3681 I was having this issue too, but my "character" was just a collision shape made in Godot. This did fix it however, so thanks!
@Alex-mr6hd
@Alex-mr6hd Жыл бұрын
@@eray3681 You're the best!
@jimsantus8927
@jimsantus8927 3 жыл бұрын
when i type + 2000 at rayend it does not work
@Conundroy
@Conundroy 2 жыл бұрын
A fix to make this work for positive local Z axis: add this line [YOUR OBJECT HERE].rotate_object_local(Vector3.UP, PI) after the look_at() function. Your player should no longer be facing backwards. Credits: godotengine.org/qa/94308/implementation-look_at-function-affect-godots-performance
@victorvatalakis5118
@victorvatalakis5118 11 ай бұрын
Bro u the best, my character was looking at an "offset" position (?) and with this line it fixed it
@felipezymor9970
@felipezymor9970 19 күн бұрын
Are you an angel?
@aleksandersanya1817
@aleksandersanya1817 8 ай бұрын
For some reason my dude keeps looking at the opposite direction even if I rotate every possible thing in the player scene 180 degrees. Edit: okay it seems to work if I make look_at from the video for the parent, and the child is turned around 180 degrees. Maybe this is wrong though, idk yet. Thank you anyways!
@b3daz
@b3daz 4 жыл бұрын
nice.
@lflm587
@lflm587 3 жыл бұрын
Everything is working but the fact that my character is flat on the ground
@BetaTester704
@BetaTester704 4 жыл бұрын
Asset Download link?
@bitmammothOG
@bitmammothOG 3 жыл бұрын
Asset? The only assets used are the floor prototype texture(it's in the Godot asset store search "Kenney"), the player is a capsule mesh with a box for a face to show which direction it's facing.
@reynold99991
@reynold99991 Жыл бұрын
Lesson learned from all this. I hate 3d in godot, my project mates wanted to make a 2.5D game, everything was going okay till we reached the weapons part. We require to throw the dynamite at a flying enemy so we put the enemy in front of the player sprite ( y co-rds for enemy 8 player y is 2), when it fires using above code it stops before or after the enemy node. I just am tired maybe I am seeing shit wrong again.
@ilucasz
@ilucasz 2 жыл бұрын
That was a really helpful video, but I am having a problem. I did everything exactly as in the video, but for some reason my character's mesh keeps pointing to the ground in the direction that the mouse is pointing. It's my fifth time watching the video to see if I've done any mistake (no joking), but I did everything the same.
@Nolkaloid
@Nolkaloid 2 жыл бұрын
Hi, it's quite hard to understand what's wrong with just a description of the issue. The character is leaning towards the ground right?
@ilucasz
@ilucasz 2 жыл бұрын
@@Nolkaloid Sorry for the poor description, but yes, the character is leaning towards the ground, as if it was looking where I point the mouse.
@Nolkaloid
@Nolkaloid 2 жыл бұрын
@@ilucasz Be sure to pass the objects own Y position in the look_at target Vector3
@ilucasz
@ilucasz 2 жыл бұрын
@@Nolkaloid Sorry to make what would be a stupid question, but... How do I do it? I mean, should I change "head.look_at(Vector3(pos.x, translation.y, pos.z), Vector3(0, 1, 0))" to "head.look_at(head.Vector3(pos.x, translation.y, pos.z), Vector3(0, 1, 0)"? Again, sorry for the stupid question, but I'm really new in programing and still not used to how it works...
@loaimallah
@loaimallah Жыл бұрын
@@ilucasz hello! try replacing "translation.y" with "Vector3.UP"... this should be the same as a Y axis.
@davedude101
@davedude101 4 жыл бұрын
mine sais parser Error: Unexpected token: Isentifier:rayOrigin
@Nolkaloid
@Nolkaloid 4 жыл бұрын
When?
@litarinn
@litarinn Жыл бұрын
is there a way to ignore player?
@litarinn
@litarinn Жыл бұрын
or intersect only with ground
@litarinn
@litarinn Жыл бұрын
I've found that intersect_ray() function takes array of objects that will be ignored as the third argument space_state.inersect_ray(from, to, [self]) also you can set collision mask as fourth argument docs.godotengine.org/en/stable/tutorial/physics/ray-casting.html#collision-mask
@davidphillips9366
@davidphillips9366 Жыл бұрын
Would this work in Godot 4?
[Godot3] How to Click 3D Objects in Godot | Game Dev Tutorial 8
6:04
GODOT TUTORIAL: Shockwave shader for noobs
15:48
Nolkaloid
Рет қаралды 52 М.
PEDRO PEDRO INSIDEOUT
00:10
MOOMOO STUDIO [무무 스튜디오]
Рет қаралды 24 МЛН
АЗАРТНИК 4 |СЕЗОН 1 Серия
40:47
Inter Production
Рет қаралды 1,1 МЛН
Godot Ray-casting tutorial: Create a simple Hitscan Weapon
6:03
Godot Quick Tip - How to use AnimationTrees
5:37
Miziziziz
Рет қаралды 95 М.
How to use Multimeshes in Godot | Game Dev Tutorial 10
8:44
Dave the Dev
Рет қаралды 30 М.
RTS Placing Buildings in Godot Tutorial - Making an RTS Series
26:57
Nanotech Gamedev
Рет қаралды 9 М.
GODOT Shaders for NOOBS - 011 Random and Noise
7:51
Pixezy
Рет қаралды 3,8 М.
Simple Interactive Grass in Godot
13:17
Kasper Frandsen
Рет қаралды 35 М.
Godot's Hidden Level/Map Editor
3:39
Garbaj
Рет қаралды 134 М.
How You Can Easily Make Your Code Simpler in Godot 4
6:59
Bitlytic
Рет қаралды 417 М.
Godot Third Person Control - Movement, Smooth Rotate
8:29
Johnny Rouddro
Рет қаралды 37 М.