From 7788f99c0a2ced6fc1b611761593f3249339f0c9 Mon Sep 17 00:00:00 2001 From: Jakob Feldmann Date: Tue, 17 Jan 2023 16:57:37 +0100 Subject: [PATCH] Further camera refinement --- src/Actors/BlobbyCam.gd | 9 +++++---- src/Actors/BlobbyCam.tscn | 4 ++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Actors/BlobbyCam.gd b/src/Actors/BlobbyCam.gd index db91492..96f8833 100644 --- a/src/Actors/BlobbyCam.gd +++ b/src/Actors/BlobbyCam.gd @@ -13,7 +13,7 @@ var camera_is_panning: bool = false var target_offset: Vector2 = Vector2(0,0) export var camera_horizontal_shift = 60 -export var offset_reset_seconds := 1 +export var offset_reset_seconds := 0.8 export var offset_adapt_seconds := 0.7 onready var shiftLeft = $CameraAnimationPlayer.get_animation("shiftingLeft") @@ -27,6 +27,7 @@ onready var screen_rect = Vector2(ProjectSettings.get_setting("display/window/si var image = Image.new() var texture = ImageTexture.new() +var prev_pos: Vector2 # Gets the camera limits from the tilemap of the level # Requires "TileMap" to be a sibling of blobby @@ -41,9 +42,9 @@ func _ready(): func _physics_process(delta: float) -> void: if(!GlobalState.is_dead): - var player_vel = blobby.velocity + var player_vel = (blobby.position - prev_pos)/delta # TODO Take average of velocity here - if(abs(player_vel.x) >= blobby.max_velocity["walk"] * 0.3): + if(abs(player_vel.x) >= blobby.max_velocity["walk"] * 0.9): move_time += delta slow_time = 0 elif(!anim_player.is_playing() && abs(player_vel.x) <= blobby.max_velocity["walk"] * 0.1): @@ -52,6 +53,7 @@ func _physics_process(delta: float) -> void: _adapt_to_movement(player_vel) position = blobby.position + prev_pos = position #TODO Do this via a event or let it be to track blobbies movement better else: self.position = blobby.global_position @@ -91,7 +93,6 @@ func _adapt_to_movement(velocity: Vector2) -> void: var center = get_camera_screen_center() var left_edge_pos = center.x - screen_rect.x/2 + camera_horizontal_shift var right_edge_pos = center.x + screen_rect.x/2 - camera_horizontal_shift - # TODO The camera jams its head to the wall repeatedly if(move_time >= offset_adapt_seconds && !anim_player.is_playing()): target_offset.x = camera_horizontal_shift * sign(velocity.x) if(offset == target_offset || diff --git a/src/Actors/BlobbyCam.tscn b/src/Actors/BlobbyCam.tscn index 7088827..63b02e0 100644 --- a/src/Actors/BlobbyCam.tscn +++ b/src/Actors/BlobbyCam.tscn @@ -631,10 +631,10 @@ texture = ExtResource( 8 ) [node name="AnimatedSprite" type="AnimatedSprite" parent="ParallaxBackground/ParallaxLayer5"] visible = false frames = SubResource( 7 ) -frame = 4 +frame = 10 playing = true [node name="AnimatedSprite2" type="AnimatedSprite" parent="ParallaxBackground/ParallaxLayer5"] frames = SubResource( 8 ) -frame = 9 +frame = 1 playing = true