summaryrefslogtreecommitdiff
path: root/demos/2d/lookat
diff options
context:
space:
mode:
authorAnton Yabchinskiy <arn@bestmx.ru>2015-07-29 23:01:36 +0300
committerAnton Yabchinskiy <arn@bestmx.ru>2015-07-29 23:01:36 +0300
commitdc8df8a91a995796f0f330bf6bb6b209f6dfce08 (patch)
tree46cfe09124703b07860754d6b44e0289422e0573 /demos/2d/lookat
parent16746f157f83d666079ba3266acec13d35b84c3f (diff)
parent922356b903061cda7591090bf19e8346c3a78cf5 (diff)
Merge branch 'master' of github.com:okamstudio/godot
Diffstat (limited to 'demos/2d/lookat')
-rw-r--r--demos/2d/lookat/arrow.pngbin0 -> 2528 bytes
-rw-r--r--demos/2d/lookat/engine.cfg4
-rw-r--r--demos/2d/lookat/lookat.gd43
-rw-r--r--demos/2d/lookat/lookat.scnbin0 -> 1622 bytes
4 files changed, 47 insertions, 0 deletions
diff --git a/demos/2d/lookat/arrow.png b/demos/2d/lookat/arrow.png
new file mode 100644
index 0000000000..25db91e8d1
--- /dev/null
+++ b/demos/2d/lookat/arrow.png
Binary files differ
diff --git a/demos/2d/lookat/engine.cfg b/demos/2d/lookat/engine.cfg
new file mode 100644
index 0000000000..56917a39ec
--- /dev/null
+++ b/demos/2d/lookat/engine.cfg
@@ -0,0 +1,4 @@
+[application]
+
+name="Look At Pointer"
+main_scene="res://lookat.scn"
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
+
+
diff --git a/demos/2d/lookat/lookat.scn b/demos/2d/lookat/lookat.scn
new file mode 100644
index 0000000000..880070b4c7
--- /dev/null
+++ b/demos/2d/lookat/lookat.scn
Binary files differ