make it easier to tell where the ball is going
This commit is contained in:
parent
5a768af1f3
commit
6a31ab76b8
7 changed files with 279 additions and 66 deletions
35
elements/player.tscn
Normal file
35
elements/player.tscn
Normal file
|
@ -0,0 +1,35 @@
|
|||
[gd_scene load_steps=4 format=3 uid="uid://cnnvwotv33u1b"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://dw0xl8644x166" path="res://elements/gravity.tscn" id="1_h0h2o"]
|
||||
[ext_resource type="PackedScene" uid="uid://df5m716pd6mej" path="res://elements/sphere.tscn" id="2_ophnk"]
|
||||
|
||||
[sub_resource type="GDScript" id="GDScript_bnqcw"]
|
||||
script/source = "extends Node
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
## Keep the ball at the center of the camera, at a distance
|
||||
$Camera.position = $Sphere.position + Vector3(0, 0, 20)
|
||||
|
||||
## Angle of the camera, so the player can see where the ball is going
|
||||
var velocity: Vector3 = $Sphere.linear_velocity
|
||||
var desired_x = max(min(velocity.y / 2, 20), -20)
|
||||
var desired_y = max(min(-velocity.x / 2, 45), -45)
|
||||
var difference_x = $Camera.rotation_degrees.x - desired_x
|
||||
var difference_y = $Camera.rotation_degrees.y - desired_y
|
||||
$Camera.rotation_degrees.x -= max(min(difference_x / 4, 3), -3)
|
||||
$Camera.rotation_degrees.y -= max(min(difference_y / 4, 3), -3)
|
||||
|
||||
## FOV of the camera, so it unzooms more at higher velocities
|
||||
const default_fov = 75
|
||||
var total_velocity = abs(velocity.x) + abs(velocity.y)
|
||||
$Camera.fov = default_fov + (total_velocity / 12)
|
||||
"
|
||||
|
||||
[node name="Player" type="Node"]
|
||||
script = SubResource("GDScript_bnqcw")
|
||||
|
||||
[node name="Gravity" parent="." instance=ExtResource("1_h0h2o")]
|
||||
|
||||
[node name="Sphere" parent="." instance=ExtResource("2_ophnk")]
|
||||
|
||||
[node name="Camera" type="Camera3D" parent="."]
|
Loading…
Add table
Add a link
Reference in a new issue