diff options
author | Juan Linietsky <reduzio@gmail.com> | 2015-05-12 08:17:09 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2015-05-12 08:17:09 -0300 |
commit | 3936ed882c6f39c74a3b124a95d5adc5e61ab3c5 (patch) | |
tree | a88b80dc67f3ca4bb6bb62b5173001f850178ca6 /demos/2d/lookat/lookat.gd | |
parent | 436379860855fe2d1b073a74f4bfa4e7acc96c5b (diff) |
-Added lookat/get_angle_to functions in 2D, and a demo, closes #1843
-Added get_viewport().get_mouse_pos() to replace Input.get_mouse_pos(), closes #1838
Diffstat (limited to 'demos/2d/lookat/lookat.gd')
-rw-r--r-- | demos/2d/lookat/lookat.gd | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/demos/2d/lookat/lookat.gd b/demos/2d/lookat/lookat.gd new file mode 100644 index 0000000000..742c5b0671 --- /dev/null +++ b/demos/2d/lookat/lookat.gd @@ -0,0 +1,43 @@ + +extends Sprite + +# member variables here, example: +# var a=2 +# var b="textvar" + +const MODE_DIRECT=0 +const MODE_CONSTANT=1 +const MODE_SMOOTH=2 + +const ROTATION_SPEED = 1 +const SMOOTH_SPEED = 2.0 + +export(int,"Direct","Constant","Smooth") var mode=MODE_DIRECT + +func _process(delta): + var mpos = get_viewport().get_mouse_pos() + + if (mode==MODE_DIRECT): + + look_at(mpos) + + elif (mode==MODE_CONSTANT): + + var ang = get_angle_to(mpos) + var s = sign(ang) + ang=abs(ang) + + rotate( min(ang,ROTATION_SPEED*delta)*s ) + + elif (mode==MODE_SMOOTH): + + var ang = get_angle_to(mpos) + + rotate( ang*delta*SMOOTH_SPEED ) + +func _ready(): + # Initialization here + set_process(true) + pass + + |