Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | DimitriyPS | |
Old Version | Published before Godot 3 was released. |
I’m learning Godot to develop in 3D. I want to build a RayCast from the camera as stated here:link
# use global coordinates, not local to node
var result = space_state.intersect_ray( Vector3(x1,y1,z1), Vector3(x2,y2,z2) )
-
Please tell me how to get it: Vector3(x1,y1,z1) and Vector3(x2,y2,z2) in global space?
-
Vector3(x2,y2,z2) - only forms a direction or limits the length of the beam (cut)?
At the end of that article there is a code example, did you check it?
Bojidar Marinov | 2016-03-24 09:23
how Bojidar Marinov said, there is a code example:
const ray_length = 1000
func _input(ev):
if ev.type==InputEvent.MOUSE_BUTTON and ev.pressed and ev.button_index==1:
var camera = get_node("camera")
var from = camera.project_ray_origin(ev.pos)
var to = from + camera.project_ray_normal(ev.pos) * ray_length
swipis | 2016-03-24 09:41
I am not able to test the code (I’m not at my PC). Just have some free time and I’m studying theory. In this case, I beg to treat with understanding, I do not know English. Reading the documentation helps me Gogle. However, the result of his translation is very difficult to perceive.
In GDScript I’m a beginner, maybe that’s why I don’t understand how this code is consistent with the method:
result = space_state.intersect_ray
I correctly understand what “var from” this is what I in the first post as noted Vector3(x1,y1,z1)? And “var to” Vector3(x2,y2,z2)?
Can I limit the length of the RayCast (to make it portion)?
DimitriyPS | 2016-03-24 10:09
Im new here as well, so I just did this in my project as well, “var from” ray “start” position and “var to” direction.
here is code I’m using:
var directState = PhysicsServer.space_get_direct_state(cam_node.get_world().get_space())
var result = directState.intersect_ray(from, to, [self])
and ray length is var so you can do what ever length you want.
swipis | 2016-03-24 22:04
How did you get the var to (direction)?
RpgGOD | 2016-03-25 07:17