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 Жыл бұрын
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 Жыл бұрын
god bless your soul
@matthewdavenport1335 Жыл бұрын
You saved my life!
@mertgulec754111 ай бұрын
thanks a lot dude I'd be bald by now if I had not seen this
@Gab_van_YouTube10 ай бұрын
It doesn't work
@kaduyeah8 ай бұрын
You sir deserve a crown
@davidmurphy5633 жыл бұрын
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.
@arkadiyviking39193 жыл бұрын
A collision object in the Godot has a function: _on_StaticBody_input_event(camera, event, click_position, click_normal, shape_idx).
@psuw4 жыл бұрын
Wow. Stunning well explained! Keep that good stuff up pls!!!
@Nolkaloid4 жыл бұрын
Thanks!^^
@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 Жыл бұрын
thank you! you just made my project very nice and simple :) and the explanation was fantastic.
@JonathanDevine4 жыл бұрын
This was incredibly helpful. Thank you! Looking forward to the next video.
@misterartyparty3 жыл бұрын
Yup, that was better that Godot docs, thanks a lot !
@First_Lst Жыл бұрын
What a great explanation. Great job.
@ahjed73974 жыл бұрын
Pls continue making random godot tut. Ur vids on point.
@Nolkaloid4 жыл бұрын
Thanks! I don't have much time and motivation right now, but I'm not planning to go anywhere :)
@ahjed73974 жыл бұрын
@@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.
@Nolkaloid4 жыл бұрын
Thanks man, appreciate it.
@greg79874 жыл бұрын
Great great tutorial! Much thanks to you.
@YourGalaxyInc4 жыл бұрын
Amazing, i helped me a lot. Thanks, good work mate.
@VroniastyGamingHD3 жыл бұрын
Very good tutorial, helped me a lot
@michkrauss2 жыл бұрын
Nice Tutorial - works fine but is there a way to make the camera only follow on x and y axis ?
@thekingbenjy2 жыл бұрын
instead of "Vector3(pos.x, 0, pos.z)" do "Vector3(pos.x, pos.y, 0)"
@ArtembAartemb2 жыл бұрын
Thank you, thank you, THANK YOU!
@nvm9174Ай бұрын
thank you so much
@ralfbierig Жыл бұрын
Nice video. What application you use to make these animations?
@TheHauntedSockdrawer4 жыл бұрын
awesome tutorial. subbed
@MadheadStardust2 жыл бұрын
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.
@Nolkaloid2 жыл бұрын
Hi, could you explain the issue in detail. I don't quite get what's your problem.
@MadheadStardust2 жыл бұрын
@@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 Жыл бұрын
Thank you lad!
@lorenzfk84323 жыл бұрын
you're a hero
@R250Tv9 ай бұрын
Hi! I don't know why but my character faces the opposite way from the mouse, does anyone know how to fix this?
@yungson78692 жыл бұрын
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?
@Nolkaloid2 жыл бұрын
Probably something to do with world / local space. Try "Transform.origin.y. "
@pand2aren4 жыл бұрын
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!
@Nolkaloid4 жыл бұрын
Hello! I'm not quite sure what you mean... Could you upload a video maybe?
@moric4677 Жыл бұрын
space_state.intersect_ray(origin,end) showing error in godot 4 alpha , it says that function expects 1 argument
@Aprch Жыл бұрын
You need to provide a PhysicsRayQueryParameters3D object. It's basically the same, just wrapped in an object. Check the manual!
@jenek07673 жыл бұрын
очень помог этот гайд. спасибо
@regularguy38793 жыл бұрын
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 ?
@Nolkaloid3 жыл бұрын
Could you provide a code snippet?
@eray36812 жыл бұрын
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.
@txvi46482 жыл бұрын
@@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 Жыл бұрын
@@eray3681 You're the best!
@jimsantus89273 жыл бұрын
when i type + 2000 at rayend it does not work
@Conundroy2 жыл бұрын
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
@victorvatalakis511811 ай бұрын
Bro u the best, my character was looking at an "offset" position (?) and with this line it fixed it
@felipezymor997019 күн бұрын
Are you an angel?
@aleksandersanya18178 ай бұрын
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!
@b3daz4 жыл бұрын
nice.
@lflm5873 жыл бұрын
Everything is working but the fact that my character is flat on the ground
@BetaTester7044 жыл бұрын
Asset Download link?
@bitmammothOG3 жыл бұрын
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 Жыл бұрын
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.
@ilucasz2 жыл бұрын
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.
@Nolkaloid2 жыл бұрын
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?
@ilucasz2 жыл бұрын
@@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.
@Nolkaloid2 жыл бұрын
@@ilucasz Be sure to pass the objects own Y position in the look_at target Vector3
@ilucasz2 жыл бұрын
@@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 Жыл бұрын
@@ilucasz hello! try replacing "translation.y" with "Vector3.UP"... this should be the same as a Y axis.
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