Further camera refinement

This commit is contained in:
Jakob Feldmann 2023-01-17 16:57:37 +01:00
parent 351e6c4916
commit 7788f99c0a
2 changed files with 7 additions and 6 deletions

View File

@ -13,7 +13,7 @@ var camera_is_panning: bool = false
var target_offset: Vector2 = Vector2(0,0) var target_offset: Vector2 = Vector2(0,0)
export var camera_horizontal_shift = 60 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 export var offset_adapt_seconds := 0.7
onready var shiftLeft = $CameraAnimationPlayer.get_animation("shiftingLeft") 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 image = Image.new()
var texture = ImageTexture.new() var texture = ImageTexture.new()
var prev_pos: Vector2
# Gets the camera limits from the tilemap of the level # Gets the camera limits from the tilemap of the level
# Requires "TileMap" to be a sibling of blobby # Requires "TileMap" to be a sibling of blobby
@ -41,9 +42,9 @@ func _ready():
func _physics_process(delta: float) -> void: func _physics_process(delta: float) -> void:
if(!GlobalState.is_dead): if(!GlobalState.is_dead):
var player_vel = blobby.velocity var player_vel = (blobby.position - prev_pos)/delta
# TODO Take average of velocity here # 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 move_time += delta
slow_time = 0 slow_time = 0
elif(!anim_player.is_playing() && abs(player_vel.x) <= blobby.max_velocity["walk"] * 0.1): 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) _adapt_to_movement(player_vel)
position = blobby.position position = blobby.position
prev_pos = position
#TODO Do this via a event or let it be to track blobbies movement better #TODO Do this via a event or let it be to track blobbies movement better
else: else:
self.position = blobby.global_position self.position = blobby.global_position
@ -91,7 +93,6 @@ func _adapt_to_movement(velocity: Vector2) -> void:
var center = get_camera_screen_center() var center = get_camera_screen_center()
var left_edge_pos = center.x - screen_rect.x/2 + camera_horizontal_shift 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 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()): if(move_time >= offset_adapt_seconds && !anim_player.is_playing()):
target_offset.x = camera_horizontal_shift * sign(velocity.x) target_offset.x = camera_horizontal_shift * sign(velocity.x)
if(offset == target_offset || if(offset == target_offset ||

View File

@ -631,10 +631,10 @@ texture = ExtResource( 8 )
[node name="AnimatedSprite" type="AnimatedSprite" parent="ParallaxBackground/ParallaxLayer5"] [node name="AnimatedSprite" type="AnimatedSprite" parent="ParallaxBackground/ParallaxLayer5"]
visible = false visible = false
frames = SubResource( 7 ) frames = SubResource( 7 )
frame = 4 frame = 10
playing = true playing = true
[node name="AnimatedSprite2" type="AnimatedSprite" parent="ParallaxBackground/ParallaxLayer5"] [node name="AnimatedSprite2" type="AnimatedSprite" parent="ParallaxBackground/ParallaxLayer5"]
frames = SubResource( 8 ) frames = SubResource( 8 )
frame = 9 frame = 1
playing = true playing = true