Advertisement
Joshua_Blackmon

Snap 3D Cursor

Oct 2nd, 2021
509
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. extends Spatial
  2. func _process(_delta):
  3.     #parent variables
  4.     var Level_node = get_parent().get_parent()
  5.     var Command_Camera = Level_node.get_child(1).get_child(0)
  6.     var ray_origin = Vector3()
  7.     var ray_target = Vector3()
  8.     var mouse_position = get_viewport().get_mouse_position()
  9.     ray_origin = Command_Camera.project_ray_origin(mouse_position)
  10.     ray_target = ray_origin + Command_Camera.project_ray_normal(mouse_position) * 1000
  11.     var space_state = get_world().direct_space_state
  12.     var intersection = space_state.intersect_ray(ray_origin, ray_target)
  13.     var Projected_cursor = Level_node.get_child(1).get_child(2)
  14.     var Cursor_3D = Level_node.get_child(1).get_child(1)
  15.  
  16.     if Input.is_action_pressed("Mouse_left"):
  17.         if not intersection.empty():
  18.             var pos = intersection.position
  19.             Projected_cursor.translation = Vector3(pos.x,pos.y,pos.z)
  20.             if Projected_cursor.translation.distance_to(translation) < 0:
  21.                 Projected_cursor.translation.distance_to(translation) * -1
  22.             if Projected_cursor.translation.distance_to(translation) < 1:
  23.                 Cursor_3D.translation = translation
  24.    
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement