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 ;)
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.
@@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.
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?
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 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.
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!
@@wongyijie5339 Yeah it doesn't work but don't worry I made it and if you are interested too I am bout to make a tutorial for it. Actually none of what everyone said here in comments worked properly. I probably will do it this weekend : th-cam.com/channels/Kqe-1ggF6A7aHGJrrfxSAA.html
@Loukpro_Godot sorry to hear. I think is better to roll with an implementation that you understand anyway. If it’s to do with rotation of a 3D object, I will be interested. My game is in isometric as well if there are tips u provide in that aspect, I will definitely be interested!
@@wongyijie5339 It provides the same outcome but in godot 4! It works with 3D objects ofc! As for isometric bcz it is 3D idk what you mean because I thought isometric can only be 2D do you might giving me an example?
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 ?
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.
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!
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.
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
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 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...
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.
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
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 ;)
god bless your soul
You saved my life!
thanks a lot dude I'd be bald by now if I had not seen this
It doesn't work
You sir deserve a crown
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.
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
Wow. Stunning well explained! Keep that good stuff up pls!!!
Thanks!^^
thank you! you just made my project very nice and simple :) and the explanation was fantastic.
A collision object in the Godot has a function: _on_StaticBody_input_event(camera, event, click_position, click_normal, shape_idx).
This was incredibly helpful. Thank you! Looking forward to the next video.
Yup, that was better that Godot docs, thanks a lot !
What a great explanation. Great job.
Pls continue making random godot tut. Ur vids on point.
Thanks! I don't have much time and motivation right now, but I'm not planning to go anywhere :)
@@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.
Thanks man, appreciate it.
Great great tutorial! Much thanks to you.
Amazing, i helped me a lot. Thanks, good work mate.
Nice Tutorial - works fine but is there a way to make the camera only follow on x and y axis ?
instead of "Vector3(pos.x, 0, pos.z)" do "Vector3(pos.x, pos.y, 0)"
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?
Probably something to do with world / local space. Try "Transform.origin.y. "
Very good tutorial, helped me a lot
Thank you, thank you, THANK YOU!
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.
Hi, could you explain the issue in detail. I don't quite get what's your problem.
@@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.
awesome tutorial. subbed
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!
Hello! I'm not quite sure what you mean... Could you upload a video maybe?
Nice video. What application you use to make these animations?
Thank you lad!
It's perfect it just doesn't work with translation due to the change of godot 3 to godot 4. Any suggestions please?
Hello there. Just use position.y instead of translation
@@wongyijie5339 Yeah it doesn't work but don't worry I made it and if you are interested too I am bout to make a tutorial for it. Actually none of what everyone said here in comments worked properly. I probably will do it this weekend : th-cam.com/channels/Kqe-1ggF6A7aHGJrrfxSAA.html
@Loukpro_Godot sorry to hear. I think is better to roll with an implementation that you understand anyway. If it’s to do with rotation of a 3D object, I will be interested. My game is in isometric as well if there are tips u provide in that aspect, I will definitely be interested!
@@wongyijie5339 It provides the same outcome but in godot 4! It works with 3D objects ofc! As for isometric bcz it is 3D idk what you mean because I thought isometric can only be 2D do you might giving me an example?
Might make a short to show what it will be like :D
thank you so much
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 ?
Could you provide a code snippet?
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.
@@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!
space_state.intersect_ray(origin,end) showing error in godot 4 alpha , it says that function expects 1 argument
You need to provide a PhysicsRayQueryParameters3D object. It's basically the same, just wrapped in an object. Check the manual!
you're a hero
очень помог этот гайд. спасибо
when i type + 2000 at rayend it does not work
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!
nice.
Asset Download link?
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.
is there a way to ignore player?
or intersect only with ground
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
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.
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?
@@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.
@@ilucasz Be sure to pass the objects own Y position in the look_at target Vector3
@@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...
@@ilucasz hello! try replacing "translation.y" with "Vector3.UP"... this should be the same as a Y axis.
Everything is working but the fact that my character is flat on the ground
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.
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
Bro u the best, my character was looking at an "offset" position (?) and with this line it fixed it
Are you an angel?
mine sais parser Error: Unexpected token: Isentifier:rayOrigin
When?
Would this work in Godot 4?