diff --git a/BodyConfig/bodyBuilderMenu.tscn b/BodyConfig/bodyBuilderMenu.tscn index ef9cb6e..5b4a7ea 100644 --- a/BodyConfig/bodyBuilderMenu.tscn +++ b/BodyConfig/bodyBuilderMenu.tscn @@ -5,6 +5,10 @@ [node name="Body Builder Menu" type="Spatial"] script = ExtResource( 2 ) +torsoPath = NodePath("Torso") +cameraPath = NodePath("GUI/HBoxC/ViewportContainer/Viewport/Camera") +rayCastPath = NodePath("GUI/HBoxC/ViewportContainer/Viewport/MouseLook") +viewPortPath = NodePath("GUI/HBoxC/ViewportContainer/Viewport") [node name="GUI" type="MarginContainer" parent="."] anchor_right = 1.0 @@ -66,4 +70,7 @@ render_target_update_mode = 3 [node name="Camera" type="Camera" parent="GUI/HBoxC/ViewportContainer/Viewport"] transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 3 ) +[node name="MouseLook" type="RayCast" parent="GUI/HBoxC/ViewportContainer/Viewport"] +enabled = true + [node name="Torso" parent="." instance=ExtResource( 1 )] diff --git a/BodyConfig/bodyBuildingScript.gd b/BodyConfig/bodyBuildingScript.gd index 194216e..e0139a8 100644 --- a/BodyConfig/bodyBuildingScript.gd +++ b/BodyConfig/bodyBuildingScript.gd @@ -1,21 +1,34 @@ extends Spatial +export(NodePath) var torsoPath +export(NodePath) var cameraPath +export(NodePath) var rayCastPath +export(NodePath) var viewPortPath + const ROT_MOD = 500 const ROT_DECLINE = 0.1 var _viewRot = false var _prev_mouse_pos +var _camera : Camera +var _rayCast : RayCast +var _torso : RigidBody +var _viewport : Viewport var _velx = 0 var _vely = 0 -var _torso : RigidBody + # 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) - _torso = get_node("Torso") - + _torso = get_node(torsoPath) as RigidBody + _camera = get_node(cameraPath) as Camera + _rayCast = get_node(rayCastPath) as RayCast + _viewport = get_node(viewPortPath) as Viewport + + func _process(delta): if _viewRot: var mouse_pos = get_viewport().get_mouse_position() @@ -38,40 +51,32 @@ func _process(delta): _velx *= decline _vely *= decline - - + func _physics_process(delta): - pass - # Get the camera - #var camera = get_node("GUI/HBoxC/ViewportContainer/Viewport/Camera") + if _viewRot: + var mouse_pos = _viewport.get_viewport().get_mouse_position() - #var mouse_pos = get_viewport().get_mouse_position() + #set origin of rayCast + var orig = _camera.project_ray_origin(mouse_pos) - # Project mouse into a 3D ray - #var ray_origin = camera.project_ray_origin(mouse_pos) - #var ray_direction = camera.project_ray_normal(mouse_pos) + #set cast_to of rayCast + _rayCast.translation = orig + _rayCast.cast_to = orig + _camera.project_ray_normal(mouse_pos) * 1000.0 + + if _rayCast.is_colliding(): + # collider will be the node hit + print(_rayCast.get_collider()) - # 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 + if _viewport.get_viewport().get_mouse_position().x >= 0: + 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