Thank you for the reply! The link you sent is very useful indeed for my other needs. Though what I want to accomplish here is to move a 3D object to the location of Touch. I set the y axis to 0 so that it’s always level to the scene. And I want to equal the x and z of an object to the x and z of Touch.
In 2D I used to write var px = event.position.x and var py = event.position.y and then under process I would write object.position.x = px and object.position.y = py
Or I would directly write under input object.position.x = event.position.x and likewise for y.
func touch_location(position, mask = 1) -> Vector3:
var camera = get_viewport().get_camera()
var ray_length = 1000
var ray_start = camera.project_ray_origin(position)
var ray_end = ray_start + camera.project_ray_normal(position) * ray_length
var space_state = camera.get_world().direct_space_state
var result = space_State.intersect_ray(ray_start, ray_end, [], mask)
if not result:
return Vector3()
return result.position
func _input(event):
if event is InputEventMouseButton:
if event.pressed:
var position = touch_location(event.position)
Huge thanks once again!
How am I supposed to set $my3Dobject position to touch_location(event.position) based on your script?
I need x and z (y is set to zero).
In 2D I used to write $my2Dobject.position.x = event.position.x and likewise for y. I have no idea how to accomplish it in 3D.