diff --git a/prefabs/gun1.tscn b/prefabs/gun1.tscn index 9d7de36..85d2191 100644 --- a/prefabs/gun1.tscn +++ b/prefabs/gun1.tscn @@ -52,7 +52,7 @@ nodes/reload_animation/node = SubResource( 19 ) nodes/reload_animation/position = Vector2( -200, 180 ) nodes/reload_one_shot/node = SubResource( 20 ) nodes/reload_one_shot/position = Vector2( 380, 100 ) -node_connections = [ "output", 0, "reload_one_shot", "TimeScale", 0, "reload_animation", "reload_one_shot", 0, "idle_animation", "reload_one_shot", 1, "TimeScale" ] +node_connections = [ "output", 0, "reload_one_shot", "reload_one_shot", 0, "idle_animation", "reload_one_shot", 1, "TimeScale", "TimeScale", 0, "reload_animation" ] [node name="Gun1" instance=ExtResource( 1 )] transform = Transform( 0.05, 0, 0, 0, 0.05, 0, 0, 0, 0.05, 0, 0, 0 ) diff --git a/scenes/warehouse.tscn b/scenes/warehouse.tscn index fefff13..cb4f105 100644 --- a/scenes/warehouse.tscn +++ b/scenes/warehouse.tscn @@ -19,7 +19,7 @@ transform = Transform( 1, 0, 0, 0, -0.965926, 0.258819, 0, -0.258819, -0.965926, shadow_enabled = true [node name="Player" parent="." instance=ExtResource( 6 )] -transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0 ) +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 2, 0 ) [node name="ConcreteFloor1" parent="." instance=ExtResource( 8 )] transform = Transform( 50, 0, 0, 0, 1, 0, 0, 0, 50, 0, 0, 0 ) diff --git a/scripts/PlayerControllerKinematic.cs b/scripts/PlayerControllerKinematic.cs index 9014812..1a9ccb2 100644 --- a/scripts/PlayerControllerKinematic.cs +++ b/scripts/PlayerControllerKinematic.cs @@ -74,6 +74,11 @@ public bool IsGrounded() return floorRayCast.IsColliding(); } + public Vector3 GetLocalVelocity() + { + return Velocity.Rotated(Vector3.Up, Rotation.y); + } + private void HandleMouseCursorVisibilityInput() { if (Input.IsActionJustPressed("toggle_mouse_cursor_visibility")) @@ -112,7 +117,18 @@ private void HandleGravity(float delta) private void HandleMovementInput(float delta) { + float maxMovementSpeed; + if (Input.IsActionPressed("sprint")) + { + maxMovementSpeed = MaxSprintMovementSpeed; + } + else + { + maxMovementSpeed = MaxMovementSpeed; + } + Vector3 inputDirection = Vector3.Zero; + Vector3 cameraRotationDegrees = camera.RotationDegrees; if (Input.IsActionPressed("move_forward")) { inputDirection -= Transform.basis.z; @@ -124,24 +140,19 @@ private void HandleMovementInput(float delta) if (Input.IsActionPressed("move_right")) { inputDirection += Transform.basis.x; + + cameraRotationDegrees.z = Mathf.Clamp(cameraRotationDegrees.z - 0.1f * maxMovementSpeed, -2f, 2f); } if (Input.IsActionPressed("move_left")) { inputDirection -= Transform.basis.x; + + cameraRotationDegrees.z = Mathf.Clamp(cameraRotationDegrees.z + 0.1f * maxMovementSpeed, -2f, 2f); } inputDirection = inputDirection.Normalized(); + camera.RotationDegrees = cameraRotationDegrees; - float maxMovementSpeed; - if (Input.IsActionPressed("sprint")) - { - targetVelocity += inputDirection * MaxSprintMovementSpeed; - maxMovementSpeed = MaxSprintMovementSpeed; - } - else - { - targetVelocity += inputDirection * MaxMovementSpeed; - maxMovementSpeed = MaxMovementSpeed; - } + targetVelocity += inputDirection * maxMovementSpeed; float decceleration = IsGrounded() ? Decceleration : 0.5f; if (inputDirection.x == 0f) @@ -202,7 +213,7 @@ private void ApplyVelocity(float delta) if (Velocity.Abs().Length() > 0.1f) { animationTree.Set("parameters/idle_walk_blend/blend_amount", Mathf.Clamp(idle_walk_blend_amount + delta, 0f, 1f)); - animationTree.Set("parameters/time_scale/scale", Velocity.Rotated(Vector3.Up, Rotation.y).Length() / MaxMovementSpeed / 2f); + animationTree.Set("parameters/time_scale/scale", GetLocalVelocity().Length() / MaxMovementSpeed / 2f); } else { @@ -211,6 +222,11 @@ private void ApplyVelocity(float delta) float time_scale = (float)animationTree.Get("parameters/time_scale/scale"); animationTree.Set("parameters/time_scale/scale", Mathf.Clamp(time_scale + delta, 0f, 1f)); } + + if (GetLocalVelocity().Abs().x < 1f) + { + camera.RotationDegrees = new Vector3(camera.RotationDegrees.x, camera.RotationDegrees.y, 0f); + } } } }