Explorar o código

Display visor ahead of mouse

DricomDragon %!s(int64=3) %!d(string=hai) anos
pai
achega
b4c375af5d
Modificáronse 2 ficheiros con 9 adicións e 1 borrados
  1. 1 0
      godot/scenes/main.tscn
  2. 8 1
      godot/scripts/Launcher.gd

+ 1 - 0
godot/scenes/main.tscn

@@ -82,6 +82,7 @@ shape = SubResource( 4 )
 
 [node name="Launcher" type="Node2D" parent="."]
 script = ExtResource( 4 )
+visor_ratio = 1.6
 
 [node name="Grid" type="TileMap" parent="Launcher" groups=[
 "grid",

+ 8 - 1
godot/scripts/Launcher.gd

@@ -1,5 +1,7 @@
 extends Node2D
 
+export (float) var visor_ratio = 1.0
+
 signal get_firing
 signal is_full
 signal gain_new_bullet
@@ -36,7 +38,12 @@ func _input(event):
 	if event is InputEventMouseButton and event.is_pressed() :
 		trigger(event.position)
 	elif event is InputEventMouseMotion and current_state == State.READY:
-		target.position = event.position
+		aim_at(event.position)
+
+
+func aim_at(cursor:Vector2):
+	target.position = source.position
+	target.position += (cursor - source.position) * visor_ratio
 
 
 func trigger(aim:Vector2):