Skip to content

Instantly share code, notes, and snippets.

@Skaruts
Last active August 11, 2019 23:27
Show Gist options
  • Save Skaruts/c6935bd215ef34807331e2a4f5ec6e67 to your computer and use it in GitHub Desktop.
Save Skaruts/c6935bd215ef34807331e2a4f5ec6e67 to your computer and use it in GitHub Desktop.
#########################################################################
# script attached to HelperPlanes.tscn, which contains:
# HelperPlanes - Spatial
# H_Helper - Area with input_event connected to the root Spatial (HelperPlanes)
# CollisionShape - containing a PlaneShape set to horizontal (everthing default)
# V_Helper - Area with input_event connected to the root Spatial (HelperPlanes)
# CollisionShape - containing a PlaneShape set to vertical (x=0, y=0, Z=1, d=0)
#
# Areas are not 'monitoring' or 'monitorable'.
#########################################################################
extends Spatial
class_name HelperPlanes
# TODO: areas can just be hidden to stop detecting input. No need to deactivate ray_pickable.
onready var camera = core.get("EditorCamera")
enum { MODE_H, MODE_V }
var current_mode = MODE_H
var _v_up = Vector3.UP
var _rad90 = deg2rad(90)
var _origin = Vector3() # original position (to reset it)
var _orot = rotation # original rotation (to reset it)
var target = null
var planes = []
func _enter_tree():
# print("entering tree")
core.add("HelperPlanes", self)
func _ready():
#func init(cam):
# camera = cam
planes.append( $H_Helper )
planes.append( $V_Helper )
hide_planes()
set_process(false)
func _process(delta):
var angle = camera.rotation
if current_mode == MODE_V:
planes[MODE_V].rotation = angle.rotated(_v_up, _rad90)
#func set_active(enable):
# planes[current_mode].set_ray_pickable(enable)
func _on_HelperPlane_input_event( camera, event, click_pos, click_normal, shape_idx ):
if target != null:
# send click information
core.notify({
kind = core.MSG_HELPER_PLANES_EVENT,
event = event,
click_pos = click_pos
})
else:
core.warning("(HelperPlanes): target is null.")
func wake():
planes[current_mode].input_ray_pickable = true
func sleep():
for p in planes:
p.input_ray_pickable = false
func help(target_obj, mode=MODE_H):
hide_planes()
target = target_obj
current_mode = mode
planes[mode].translation = target.translation
planes[mode].visible = true
wake()
if mode == MODE_V:
set_process(true)
# print("target: ", target)
func dismiss():
hide_planes()
# current_mode = MODE_NONE
sleep()
target = null
set_process(false)
for p in planes:
translation = _origin
# p.set_ray_pickable(false)
func hide_planes():
for p in planes:
p.visible = false
func set_pos(pos):
translation = pos
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment