浏览代码

Make the camera zoom when distance increase

Distance increase between players.
DricomDragon 5 年之前
父节点
当前提交
7acaacfc1e
共有 2 个文件被更改,包括 11 次插入1 次删除
  1. 10 0
      Game.gd
  2. 1 1
      Player.tscn

+ 10 - 0
Game.gd

@@ -3,6 +3,8 @@ extends Node2D
 var cam
 var p1
 var p2
+var dist_max = 900
+var zoom_rate = 0.001
 
 func _ready():
 	cam = $Grid/Camera1
@@ -11,3 +13,11 @@ func _ready():
 
 func _process(d):
 	cam.position = 0.5 * (p1.position + p2.position)
+
+	var dist = (p1.position).distance_to(p2.position)
+
+	if dist < dist_max:
+		cam.zoom = Vector2(1.0, 1.0)
+	else:
+		var zoom = 1.0 + (dist - dist_max) * zoom_rate
+		cam.zoom = Vector2(zoom, zoom)

+ 1 - 1
Player.tscn

@@ -51,5 +51,5 @@ __meta__ = {
 
 [node name="Tween" type="Tween" parent="."]
 script = ExtResource( 3 )
-duration = 0.25
+duration = 0.1
 [connection signal="body_entered" from="." to="." method="_on_crash"]