2015-01-21 16:54:17 +00:00
|
|
|
|
|
|
|
extends Spatial
|
|
|
|
|
2015-11-21 12:31:25 +00:00
|
|
|
# Member variables
|
2015-01-21 16:54:17 +00:00
|
|
|
var r_pos = Vector2()
|
|
|
|
var state
|
|
|
|
|
2015-12-09 07:38:23 +00:00
|
|
|
const STATE_MENU = 0
|
|
|
|
const STATE_GRAB = 1
|
|
|
|
|
2015-01-21 16:54:17 +00:00
|
|
|
|
|
|
|
func direction(vector):
|
2015-12-09 07:38:23 +00:00
|
|
|
var v = get_node("Camera").get_global_transform().basis*vector
|
2015-01-21 16:54:17 +00:00
|
|
|
v = v.normalized()
|
|
|
|
return v
|
|
|
|
|
|
|
|
|
|
|
|
func impulse(event, action):
|
|
|
|
if(event.is_action(action) && event.is_pressed() && !event.is_echo()):
|
|
|
|
return true
|
|
|
|
else:
|
|
|
|
return false
|
|
|
|
|
|
|
|
|
|
|
|
func _fixed_process(delta):
|
|
|
|
if(state != STATE_GRAB):
|
|
|
|
return
|
|
|
|
|
|
|
|
if(Input.get_mouse_mode() != Input.MOUSE_MODE_CAPTURED):
|
|
|
|
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
|
|
|
|
|
2015-11-21 12:31:25 +00:00
|
|
|
var dir = Vector3()
|
2015-01-21 16:54:17 +00:00
|
|
|
var cam = get_global_transform()
|
|
|
|
var org = get_translation()
|
|
|
|
|
|
|
|
if (Input.is_action_pressed("move_forward")):
|
2015-12-09 07:38:23 +00:00
|
|
|
dir += direction(Vector3(0, 0, -1))
|
2015-01-21 16:54:17 +00:00
|
|
|
if (Input.is_action_pressed("move_backwards")):
|
2015-12-09 07:38:23 +00:00
|
|
|
dir += direction(Vector3(0, 0, 1))
|
2015-01-21 16:54:17 +00:00
|
|
|
if (Input.is_action_pressed("move_left")):
|
2015-12-09 07:38:23 +00:00
|
|
|
dir += direction(Vector3(-1, 0, 0))
|
2015-01-21 16:54:17 +00:00
|
|
|
if (Input.is_action_pressed("move_right")):
|
2015-12-09 07:38:23 +00:00
|
|
|
dir += direction(Vector3(1, 0, 0))
|
2015-01-21 16:54:17 +00:00
|
|
|
|
|
|
|
dir = dir.normalized()
|
|
|
|
|
2015-12-09 07:38:23 +00:00
|
|
|
move(dir*10*delta)
|
|
|
|
var d = delta*0.1
|
2015-01-21 16:54:17 +00:00
|
|
|
|
2015-12-09 07:38:23 +00:00
|
|
|
var yaw = get_transform().rotated(Vector3(0, 1, 0), d*r_pos.x)
|
2015-01-21 16:54:17 +00:00
|
|
|
set_transform(yaw)
|
|
|
|
|
|
|
|
var cam = get_node("Camera")
|
2015-12-09 07:38:23 +00:00
|
|
|
var pitch = cam.get_transform().rotated(Vector3(1, 0, 0), d*r_pos.y)
|
2015-01-21 16:54:17 +00:00
|
|
|
cam.set_transform(pitch)
|
|
|
|
|
|
|
|
r_pos.x = 0.0
|
|
|
|
r_pos.y = 0.0
|
|
|
|
|
|
|
|
|
2015-12-09 07:38:23 +00:00
|
|
|
func _input(event):
|
2015-01-21 16:54:17 +00:00
|
|
|
if(event.type == InputEvent.MOUSE_MOTION):
|
|
|
|
r_pos = event.relative_pos
|
|
|
|
|
|
|
|
if(impulse(event, "ui_cancel")):
|
|
|
|
if(state == STATE_GRAB):
|
|
|
|
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
|
|
|
|
state = STATE_MENU
|
|
|
|
else:
|
|
|
|
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
|
|
|
|
state = STATE_GRAB
|
|
|
|
|
|
|
|
|
|
|
|
func _ready():
|
|
|
|
set_fixed_process(true)
|
|
|
|
set_process_input(true)
|
|
|
|
|
|
|
|
state = STATE_MENU
|