| … | … | @@ -1,8 +1,5 @@ |
| 1 | 1 | extends Spatial |
| 2 | 2 | |
| 3 | var ballCamera : Camera | |
| 4 | var ball : RigidBody | |
| 5 | ||
| 6 | 3 | signal player_request_join |
| 7 | 4 | |
| 8 | 5 | |
| … | … | @@ -13,11 +10,7 @@ signal player_request_join |
| 13 | 10 | |
| 14 | 11 | # Called when the node enters the scene tree for the first time. |
| 15 | 12 | func _ready(): |
| 16 | # Attach Camera to Player Ball | |
| 17 | ball = get_tree().get_current_scene().get_node("player_ball") | |
| 18 | ballCamera = get_tree().get_current_scene().get_node("Camera") | |
| 19 | ||
| 20 | ||
| 13 | pass | |
| 21 | 14 | |
| 22 | 15 | # Called every frame. 'delta' is the elapsed time since the previous frame. |
| 23 | 16 | #func _process(delta): |
| … | … | @@ -1,4 +1,4 @@ |
| 1 | [gd_scene load_steps=7 format=2] | |
| 1 | [gd_scene load_steps=9 format=2] | |
| 2 | 2 | |
| 3 | 3 | [ext_resource path="res://assets/levels/level0/assets_level_0.tscn" type="PackedScene" id=1] |
| 4 | 4 | [ext_resource path="res://levels/spawn_point/spawn_point.tscn" type="PackedScene" id=2] |
| … | … | @@ -6,6 +6,8 @@ |
| 6 | 6 | [ext_resource path="res://player/ball/player_ball.tscn" type="PackedScene" id=4] |
| 7 | 7 | [ext_resource path="res://special_input.gd" type="Script" id=5] |
| 8 | 8 | [ext_resource path="res://ui/debug/ball/ui_debug_ball.tscn" type="PackedScene" id=6] |
| 9 | [ext_resource path="res://player/camera/player_camera.tscn" type="PackedScene" id=7] | |
| 10 | [ext_resource path="res://player/camera/player_camera.gd" type="Script" id=8] | |
| 9 | 11 | |
| 10 | 12 | [node name="Spatial" type="Spatial"] |
| 11 | 13 | script = ExtResource( 3 ) |
| … | … | @@ -13,15 +15,13 @@ script = ExtResource( 3 ) |
| 13 | 15 | [node name="level_0" parent="." instance=ExtResource( 1 )] |
| 14 | 16 | transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 1.178, 1.877, -3.673 ) |
| 15 | 17 | |
| 16 | [node name="Position3D" type="Position3D" parent="."] | |
| 18 | [node name="player_ball" parent="." instance=ExtResource( 4 )] | |
| 19 | transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -0.733258, 2.26544, -8.91449 ) | |
| 17 | 20 | |
| 18 | [node name="player_ball" parent="Position3D" instance=ExtResource( 4 )] | |
| 19 | transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -0.733258, 1.63307, -8.91449 ) | |
| 20 | ||
| 21 | [node name="ballCamera" type="Camera" parent="Position3D"] | |
| 22 | transform = Transform( 1, 0, 0, 0, 0.819152, 0.573577, 0, -0.573577, 0.819152, 1.032, 15, 13.59 ) | |
| 23 | fov = 10.0 | |
| 24 | size = 17.0 | |
| 21 | [node name="player_camera" parent="." instance=ExtResource( 7 )] | |
| 22 | pause_mode = 2 | |
| 23 | script = ExtResource( 8 ) | |
| 24 | player_ball = NodePath("../player_ball") | |
| 25 | 25 | |
| 26 | 26 | [node name="spawn_point" parent="." instance=ExtResource( 2 )] |
| 27 | 27 | transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 11.446, 6.01065, -19.7949 ) |
| … | … | @@ -40,3 +40,6 @@ transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 17.8105, 5.36633, -12.0799 ) |
| 40 | 40 | script = ExtResource( 5 ) |
| 41 | 41 | |
| 42 | 42 | [node name="DebugUI" parent="." instance=ExtResource( 6 )] |
| 43 | ||
| 44 | [node name="CameraTween" type="Tween" parent="."] | |
| 45 | pause_mode = 2 |
| … | … | @@ -1,81 +1,73 @@ |
| 1 | 1 | extends RigidBody |
| 2 | 2 | |
| 3 | 3 | var rolling_force = 10 |
| 4 | var rolling_force_max : float = 50 | |
| 4 | 5 | var bFirstPersonCamera = false |
| 5 | 6 | var bDebugPaused : bool = false |
| 6 | 7 | var ballCameraOriginalOrigin : Vector3 |
| 7 | var fCameraGoalFoV : float = 10 | |
| 8 | 8 | |
| 9 | var vBallCameraRotation : Vector3 | |
| 10 | ||
| 11 | var ballCamera : Camera | |
| 12 | 9 | var lVelocity : Label |
| 13 | var lCameraAngle : Label | |
| 10 | var lAngularVelocity : Label | |
| 14 | 11 | |
| 15 | 12 | func _ready(): |
| 16 | ballCamera = $ballCamera | |
| 17 | if !ballCamera: | |
| 18 | ballCamera = get_tree().get_current_scene().get_node("Position3D").get_node("ballCamera") | |
| 19 | if !ballCamera: | |
| 20 | ballCamera = get_tree().get_current_scene().get_node("ballCamera") | |
| 21 | if !ballCamera: | |
| 22 | ballCamera = get_node("ballCamera") | |
| 23 | ballCamera.set_as_toplevel(true) | |
| 24 | lVelocity = get_tree().get_current_scene().get_node("DebugUI").get_node("Velocity_Real") | |
| 25 | lCameraAngle = get_tree().get_current_scene().get_node("DebugUI").get_node("CameraAngle_Real") | |
| 26 | # Backup Camera Transform | |
| 27 | if ballCamera: | |
| 28 | ballCameraOriginalOrigin = ballCamera.global_transform.origin | |
| 29 | vBallCameraRotation = ballCamera.rotation | |
| 13 | lVelocity = get_tree().get_current_scene().get_node("DebugUI").get_node("BallVelocity_Value") | |
| 14 | lAngularVelocity = get_tree().get_current_scene().get_node("DebugUI").get_node("BallAngularVelocity_Value") | |
| 30 | 15 | |
| 31 | func _process(delta: float) -> void: | |
| 32 | ballCamera.fov = move_toward(ballCamera.fov, fCameraGoalFoV, 8 * delta) | |
| 16 | func _process(_delta: float) -> void: | |
| 17 | pass | |
| 33 | 18 | |
| 19 | func checkAngularVelocity(delta : float, angVelocity : float, bAdd : bool) -> float: | |
| 20 | if bAdd: | |
| 21 | angVelocity = angVelocity + rolling_force*delta | |
| 22 | else: | |
| 23 | angVelocity = angVelocity - rolling_force*delta | |
| 24 | ||
| 25 | var cappedVelocity = min(rolling_force_max, abs(angVelocity) ) | |
| 26 | if (angVelocity < 0): | |
| 27 | return cappedVelocity * -1 | |
| 28 | else: | |
| 29 | return cappedVelocity | |
| 34 | 30 | |
| 35 | 31 | func _physics_process(delta: float) -> void: |
| 36 | ||
| 37 | ballCamera.translate( Vector3(0.001, 0.0, 0.0)) | |
| 38 | #if ballCamera: | |
| 39 | # ballCamera.rotation = (vBallCameraRotation) | |
| 40 | ||
| 41 | if Input.is_action_just_pressed("camera_toggle_fps"): | |
| 42 | if bFirstPersonCamera == true: | |
| 43 | bFirstPersonCamera = false | |
| 44 | ballCamera.global_transform.origin = ballCameraOriginalOrigin | |
| 45 | else: | |
| 46 | bFirstPersonCamera = true | |
| 32 | #if Input.is_action_just_pressed("camera_toggle_fps"): | |
| 33 | # if bFirstPersonCamera == true: | |
| 34 | # bFirstPersonCamera = false | |
| 35 | # ballCamera.global_transform.origin = ballCameraOriginalOrigin | |
| 36 | # else: | |
| 37 | # bFirstPersonCamera = true | |
| 47 | 38 | |
| 48 | 39 | if bDebugPaused: |
| 49 | 40 | return |
| 50 | 41 | |
| 51 | if false: | |
| 52 | ballCamera.global_transform.origin = lerp( | |
| 53 | ballCamera.global_transform.origin, | |
| 54 | global_transform.origin, 1.0 | |
| 55 | ) | |
| 56 | ballCamera.global_transform.origin = lerp( | |
| 57 | ballCamera.global_transform.origin, | |
| 58 | global_transform.origin, 1.0 | |
| 59 | ) | |
| 42 | #if false: | |
| 43 | # ballCamera.global_transform.origin = lerp( | |
| 44 | # ballCamera.global_transform.origin, | |
| 45 | # global_transform.origin, 1.0 | |
| 46 | # ) | |
| 47 | # ballCamera.global_transform.origin = lerp( | |
| 48 | # ballCamera.global_transform.origin, | |
| 49 | # global_transform.origin, 1.0 | |
| 50 | # ) | |
| 60 | 51 | |
| 61 | if Input.is_action_just_released("camera_zoom_in"): | |
| 62 | fCameraGoalFoV += -2 | |
| 63 | elif Input.is_action_just_released("camera_zoom_out"): | |
| 64 | fCameraGoalFoV += 2 | |
| 52 | ||
| 65 | 53 | |
| 66 | 54 | #$FloorCheck.global_transform.origin = global_transform.origin |
| 67 | 55 | if Input.is_action_pressed("ball_roll_up"): |
| 68 | angular_velocity.x -= rolling_force*delta | |
| 56 | # angular_velocity.x = checkAngularVelocity(delta, angular_velocity.x, false) | |
| 57 | angular_velocity.x = clamp(angular_velocity.x - rolling_force*delta, rolling_force_max * -1, rolling_force_max) | |
| 69 | 58 | elif Input.is_action_pressed("ball_roll_down"): |
| 70 | angular_velocity.x += rolling_force*delta | |
| 59 | # angular_velocity.x = checkAngularVelocity(delta, angular_velocity.x, true) | |
| 60 | angular_velocity.x = clamp(angular_velocity.x + rolling_force*delta, rolling_force_max * -1, rolling_force_max) | |
| 71 | 61 | if Input.is_action_pressed("ball_roll_left"): |
| 72 | angular_velocity.z += rolling_force*delta | |
| 62 | #angular_velocity.z = checkAngularVelocity(delta, angular_velocity.z, true) | |
| 63 | angular_velocity.z = clamp(angular_velocity.z + rolling_force*delta, rolling_force_max * -1, rolling_force_max) | |
| 73 | 64 | elif Input.is_action_pressed("ball_roll_right"): |
| 74 | angular_velocity.z -= rolling_force*delta | |
| 65 | #angular_velocity.z = checkAngularVelocity(delta, angular_velocity.z, false) | |
| 66 | angular_velocity.z = clamp(angular_velocity.z - rolling_force*delta, rolling_force_max * -1, rolling_force_max) | |
| 75 | 67 | |
| 76 | 68 | #if Input.is_action_just_pressed("jump") and $FloorCheck.is_colliding(): |
| 77 | 69 | # apply_impulse(Vector3(), Vector3.UP*1000) |
| 78 | 70 | |
| 79 | 71 | # Update Debug UI |
| 80 | 72 | lVelocity.text = String(self.linear_velocity) |
| 81 | lCameraAngle.text = String(self.rotation) | |
| 73 | lAngularVelocity.text = String(self.angular_velocity) |
| … | … | @@ -17,3 +17,9 @@ transform = Transform( 0.1, 0, 0, 0, 0.1, 0, 0, 0, 0.1, 0, 0, 0 ) |
| 17 | 17 | shape = SubResource( 1 ) |
| 18 | 18 | |
| 19 | 19 | [node name="asset" parent="." instance=ExtResource( 1 )] |
| 20 | ||
| 21 | [node name="OmniLight" type="OmniLight" parent="."] | |
| 22 | light_color = Color( 0, 0.717647, 1, 1 ) | |
| 23 | light_energy = 16.0 | |
| 24 | light_bake_mode = 0 | |
| 25 | omni_range = 0.174 |
| … | … | @@ -0,0 +1,35 @@ |
| 1 | extends Camera | |
| 2 | ||
| 3 | export(NodePath) var player_ball : NodePath | |
| 4 | onready var ball = get_node(player_ball) | |
| 5 | onready var offset = ball.to_local(global_transform.origin) | |
| 6 | ||
| 7 | var fCameraGoalFoV : float | |
| 8 | var lCameraAngle : Label | |
| 9 | var tween : Tween | |
| 10 | ||
| 11 | func _ready(): | |
| 12 | fCameraGoalFoV = fov | |
| 13 | lCameraAngle = get_tree().get_current_scene().get_node("DebugUI").get_node("CameraAngle_Real") | |
| 14 | tween = get_tree().get_current_scene().get_node("CameraTween") | |
| 15 | ||
| 16 | func _process(_delta): | |
| 17 | # Update Camera Position | |
| 18 | global_transform.origin.y = ball.global_transform.origin.y + offset.y + 1.00 | |
| 19 | global_transform.origin.z = ball.global_transform.origin.z + offset.z | |
| 20 | ||
| 21 | # Check for Camera-Related Inputs | |
| 22 | if Input.is_action_just_released("camera_zoom_in"): | |
| 23 | fCameraGoalFoV = max(5, fCameraGoalFoV - 2) | |
| 24 | tween.remove_all() | |
| 25 | tween.interpolate_property(self, "fov", | |
| 26 | self.fov, fCameraGoalFoV, 1, | |
| 27 | Tween.TRANS_QUINT, Tween.EASE_OUT) | |
| 28 | tween.start() | |
| 29 | elif Input.is_action_just_released("camera_zoom_out"): | |
| 30 | fCameraGoalFoV = min(20, fCameraGoalFoV + 2) | |
| 31 | tween.remove_all() | |
| 32 | tween.interpolate_property(self, "fov", | |
| 33 | self.fov, fCameraGoalFoV, 1, | |
| 34 | Tween.TRANS_QUINT, Tween.EASE_OUT) | |
| 35 | tween.start() |
| … | … | @@ -0,0 +1,5 @@ |
| 1 | [gd_scene format=2] | |
| 2 | ||
| 3 | [node name="Camera" type="Camera"] | |
| 4 | transform = Transform( 1, 0, 0, 0, 0.819152, 0.573577, 0, -0.573577, 0.819152, 1.032, 15, 13.59 ) | |
| 5 | fov = 10.0 |
| … | … | @@ -7,33 +7,35 @@ __meta__ = { |
| 7 | 7 | "_edit_use_anchors_": false |
| 8 | 8 | } |
| 9 | 9 | |
| 10 | [node name="Velocity" type="Label" parent="."] | |
| 10 | [node name="BallVelocity" type="Label" parent="."] | |
| 11 | margin_left = 39.0 | |
| 11 | 12 | margin_top = 52.0 |
| 12 | margin_right = 104.0 | |
| 13 | margin_right = 178.0 | |
| 13 | 14 | margin_bottom = 66.0 |
| 14 | text = "Velocity :" | |
| 15 | text = "Ball Velocity :" | |
| 15 | 16 | align = 2 |
| 16 | 17 | |
| 17 | [node name="CameraAngle" type="Label" parent="."] | |
| 18 | margin_top = 77.0 | |
| 19 | margin_right = 104.0 | |
| 20 | margin_bottom = 91.0 | |
| 21 | text = "Camera Angle :" | |
| 22 | align = 2 | |
| 23 | ||
| 24 | [node name="Velocity_Real" type="Label" parent="."] | |
| 25 | margin_left = 111.0 | |
| 18 | [node name="BallVelocity_Value" type="Label" parent="."] | |
| 19 | margin_left = 186.0 | |
| 26 | 20 | margin_top = 52.0 |
| 27 | margin_right = 565.0 | |
| 21 | margin_right = 640.0 | |
| 28 | 22 | margin_bottom = 66.0 |
| 29 | 23 | __meta__ = { |
| 30 | 24 | "_edit_use_anchors_": false |
| 31 | 25 | } |
| 32 | 26 | |
| 33 | [node name="CameraAngle_Real" type="Label" parent="."] | |
| 34 | margin_left = 111.0 | |
| 27 | [node name="BallAngularVelocity" type="Label" parent="."] | |
| 28 | margin_left = 39.0 | |
| 29 | margin_top = 77.0 | |
| 30 | margin_right = 178.0 | |
| 31 | margin_bottom = 91.0 | |
| 32 | text = "Ball Angular Velocity :" | |
| 33 | align = 2 | |
| 34 | ||
| 35 | [node name="BallAngularVelocity_Value" type="Label" parent="."] | |
| 36 | margin_left = 186.0 | |
| 35 | 37 | margin_top = 77.0 |
| 36 | margin_right = 565.0 | |
| 38 | margin_right = 640.0 | |
| 37 | 39 | margin_bottom = 91.0 |
| 38 | 40 | __meta__ = { |
| 39 | 41 | "_edit_use_anchors_": false |