Skip to content

Commit

Permalink
new camera
Browse files Browse the repository at this point in the history
  • Loading branch information
janekx21 committed Jan 22, 2024
1 parent 21e11a6 commit 873ee40
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
29 changes: 24 additions & 5 deletions code/CameraFollow.gd
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,29 @@ extends Camera3D
@export var offset = Vector3(0, 5, 4)
@export var move_speed = 5

var velocity = Vector3.ZERO
var velocity2 = Vector3.ZERO
var look_target = Vector3.ZERO

func _process(delta: float) -> void:
var target_position = target.global_position + offset
var distance = target_position.distance_to(global_position)
var move_delta = delta * move_speed * distance
# Selfmade smooth camera follower
# Fell free to modify and improve

velocity = velocity.move_toward(
(
(target.global_position + offset)
- global_position
) - (velocity.normalized() * pow(velocity.length(), 0.8) * 10)
, delta * 0.2
)
velocity *= 0.99
global_position += velocity

global_position = global_position.move_toward(target_position, move_delta)
look_at(target.global_position)
velocity2 = velocity2.move_toward(
(target.global_position - look_target) - (velocity2.normalized()
* pow(velocity2.length(), .5) * 2)
, delta * 0.5
)
velocity2 *= 0.95
look_target += velocity2
look_at(look_target)
1 change: 0 additions & 1 deletion code/player.gd
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ func _physics_process(delta: float) -> void:
velocity.z = planar_velocity.y
velocity.y -= delta * 50


move_and_slide()


Expand Down
10 changes: 9 additions & 1 deletion scenes/game.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=12 format=3 uid="uid://b51ha0wsiwdnk"]
[gd_scene load_steps=14 format=3 uid="uid://b51ha0wsiwdnk"]

[ext_resource type="Script" path="res://code/CameraFollow.gd" id="1_vlvop"]
[ext_resource type="PackedScene" uid="uid://c6clkgmt6mj40" path="res://scenes/player.tscn" id="1_yng7m"]
Expand All @@ -10,8 +10,14 @@
[ext_resource type="Script" path="res://code/HeartDisplay.gd" id="8_7ok87"]
[ext_resource type="Texture2D" uid="uid://cp47nfegye1qs" path="res://tex/suit_hearts.png" id="9_7vmu5"]

[sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_8g0j4"]

[sub_resource type="Sky" id="Sky_7vv3c"]
sky_material = SubResource("ProceduralSkyMaterial_8g0j4")

[sub_resource type="Environment" id="Environment_ktnj1"]
background_mode = 2
sky = SubResource("Sky_7vv3c")
ambient_light_color = Color(0.282353, 0.352941, 0.407843, 1)
tonemap_mode = 2

Expand All @@ -26,9 +32,11 @@ target = NodePath("../Player")

[node name="Player" parent="." instance=ExtResource("1_yng7m")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0)
floor_constant_speed = true

[node name="DirectionalLight3D" type="DirectionalLight3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 0.337818, 0.941211, 0, -0.941211, 0.337818, -6.28612, 0.125248, 0.0914339)
shadow_enabled = true

[node name="World" type="Node" parent="."]

Expand Down

0 comments on commit 873ee40

Please sign in to comment.