diff options
author | Rémi Verschelde <remi@verschelde.fr> | 2015-12-09 08:49:06 +0100 |
---|---|---|
committer | Rémi Verschelde <remi@verschelde.fr> | 2015-12-09 08:49:06 +0100 |
commit | db9da152765357c5e484792fc5e31a25acbc7616 (patch) | |
tree | f58497abcecc0a74d3d12132f134a5e0b279cc24 /demos/misc/window_management/observer/observer.gd | |
parent | efbb834936fdc9da9789ad37c9cc61e0b90cda95 (diff) | |
parent | 52d515b611ed1f593e23b0adabedbd9fd59dc7db (diff) |
Merge pull request #2853 from akien-mga/pr-demos-code-formatting
Improve demos code formatting and update to 2.0
Diffstat (limited to 'demos/misc/window_management/observer/observer.gd')
-rw-r--r-- | demos/misc/window_management/observer/observer.gd | 31 |
1 files changed, 15 insertions, 16 deletions
diff --git a/demos/misc/window_management/observer/observer.gd b/demos/misc/window_management/observer/observer.gd index d27912a670..f100811859 100644 --- a/demos/misc/window_management/observer/observer.gd +++ b/demos/misc/window_management/observer/observer.gd @@ -1,16 +1,17 @@ extends Spatial +# Member variables var r_pos = Vector2() var state -const STATE_MENU=0 -const STATE_GRAB=1 +const STATE_MENU = 0 +const STATE_GRAB = 1 + func direction(vector): - var v = get_node("Camera").get_global_transform().basis * vector + var v = get_node("Camera").get_global_transform().basis*vector v = v.normalized() - return v @@ -22,43 +23,42 @@ func impulse(event, action): 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) - var dir = Vector3() + var dir = Vector3() var cam = get_global_transform() var org = get_translation() if (Input.is_action_pressed("move_forward")): - dir += direction(Vector3(0,0,-1)) + dir += direction(Vector3(0, 0, -1)) if (Input.is_action_pressed("move_backwards")): - dir += direction(Vector3(0,0,1)) + dir += direction(Vector3(0, 0, 1)) if (Input.is_action_pressed("move_left")): - dir += direction(Vector3(-1,0,0)) + dir += direction(Vector3(-1, 0, 0)) if (Input.is_action_pressed("move_right")): - dir += direction(Vector3(1,0,0)) + dir += direction(Vector3(1, 0, 0)) dir = dir.normalized() - move(dir * 10 * delta) - var d = delta * 0.1 + move(dir*10*delta) + var d = delta*0.1 - var yaw = get_transform().rotated(Vector3(0,1,0), d * r_pos.x) + var yaw = get_transform().rotated(Vector3(0, 1, 0), d*r_pos.x) set_transform(yaw) var cam = get_node("Camera") - var pitch = cam.get_transform().rotated(Vector3(1,0,0), d * r_pos.y) + var pitch = cam.get_transform().rotated(Vector3(1, 0, 0), d*r_pos.y) cam.set_transform(pitch) r_pos.x = 0.0 r_pos.y = 0.0 -func _input( event ): +func _input(event): if(event.type == InputEvent.MOUSE_MOTION): r_pos = event.relative_pos @@ -76,4 +76,3 @@ func _ready(): set_process_input(true) state = STATE_MENU - |