62 lines
1.5 KiB
GDScript
62 lines
1.5 KiB
GDScript
extends Spatial
|
|
|
|
const ROT_MOD = 10
|
|
|
|
|
|
var _viewRot = false
|
|
var _prev_mouse_pos
|
|
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
func _ready():
|
|
PhysicsServer.area_set_param(get_viewport().find_world().get_space(), PhysicsServer.AREA_PARAM_GRAVITY, 0)
|
|
|
|
|
|
func _physics_process(delta):
|
|
if _viewRot:
|
|
var mouse_pos = get_viewport().get_mouse_position()
|
|
|
|
var x_dif = mouse_pos.x - _prev_mouse_pos.x
|
|
var y_dif = mouse_pos.y - _prev_mouse_pos.y
|
|
|
|
print (x_dif)
|
|
print (y_dif)
|
|
|
|
rotate_x(x_dif * ROT_MOD * delta * PI/180 - global_transform.basis.get_euler().y)
|
|
rotate_y(y_dif * ROT_MOD * delta * PI/180 - global_transform.basis.get_euler().y)
|
|
|
|
_prev_mouse_pos = mouse_pos
|
|
|
|
# Get the camera
|
|
#var camera = get_node("GUI/HBoxC/ViewportContainer/Viewport/Camera")
|
|
|
|
#var mouse_pos = get_viewport().get_mouse_position()
|
|
|
|
# Project mouse into a 3D ray
|
|
#var ray_origin = camera.project_ray_origin(mouse_pos)
|
|
#var ray_direction = camera.project_ray_normal(mouse_pos)
|
|
|
|
# Cast a ray
|
|
#var from = ray_origin
|
|
#var to = ray_origin + ray_direction * 1000.0
|
|
#var space_state = get_world().get_direct_space_state()
|
|
#var hit = space_state.intersect_ray(from, to)
|
|
|
|
#print("test")
|
|
|
|
#if hit.size() != 0:
|
|
# collider will be the node you hit
|
|
#print(hit.collider)
|
|
#pass
|
|
|
|
func _input(event):
|
|
if event is InputEventMouseButton:
|
|
if event.pressed:
|
|
print("Mouse Click at: ", event.position)
|
|
_prev_mouse_pos = event.position
|
|
_viewRot = true
|
|
else:
|
|
print("mouse unpressed at: ", event.position)
|
|
_viewRot = false
|
|
|