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!
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.
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)
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!
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
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.
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
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?
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??
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
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
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!
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!
Pinning
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.
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)
Single greatest godot tutorial ever made, and I've watched hundreds. Please keep doing this.
i love how to the point your tutorials are
Great tutorial as always, thank you!
Thank you, this helped me figure out exactly what I needed to know.
perfect .. Thanks
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!
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
Thanks
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
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.
is there any way to add exceptions? like in a traditional raycast3D node
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
How do you figure out all those methods? (talking about in general)
Searching the online manual is always so clunky.
Good video as always. 👍
Google, Godot forums, and mainly Godot Documentation
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?
If they aren't rigidbodies they can't fall through the floor
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??
Instead of the three lines inside the 'if' write (where Node is the object you want to move): Node.position = raycast_result['position]
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
me too I have the same problem and can't find a solution can someone please help
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
Thanks a lot. The tutorial is clear and simple.
plz make blender tutorial
but Im the Godot wizz
спасибо братан!
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!
First
confirmed
I don't understand. I don't know the principle, haha..
you're shooting a ray from the camera, to the point on the mesh
what about orbit around an object, I have a hacky way which does no work well ...if you have an idea you can help