Camera refinements
This commit is contained in:
parent
b7deb8855c
commit
351e6c4916
@ -12,9 +12,9 @@ var original_limit_top: int
|
||||
var camera_is_panning: bool = false
|
||||
var target_offset: Vector2 = Vector2(0,0)
|
||||
|
||||
export var camera_horizontal_shift = 80
|
||||
export var camera_horizontal_shift = 60
|
||||
export var offset_reset_seconds := 1
|
||||
export var offset_adapt_seconds := 0.8
|
||||
export var offset_adapt_seconds := 0.7
|
||||
|
||||
onready var shiftLeft = $CameraAnimationPlayer.get_animation("shiftingLeft")
|
||||
onready var shiftRight = $CameraAnimationPlayer.get_animation("shiftingRight")
|
||||
@ -42,14 +42,16 @@ func _ready():
|
||||
func _physics_process(delta: float) -> void:
|
||||
if(!GlobalState.is_dead):
|
||||
var player_vel = blobby.velocity
|
||||
if(abs(player_vel.x) >= blobby.max_velocity["walk"]):
|
||||
# TODO Take average of velocity here
|
||||
if(abs(player_vel.x) >= blobby.max_velocity["walk"] * 0.3):
|
||||
move_time += delta
|
||||
slow_time = 0
|
||||
else:
|
||||
elif(!anim_player.is_playing() && abs(player_vel.x) <= blobby.max_velocity["walk"] * 0.1):
|
||||
slow_time += delta
|
||||
move_time = 0
|
||||
|
||||
_adapt_to_movement(player_vel)
|
||||
position = blobby.position
|
||||
#TODO Do this via a event or let it be to track blobbies movement better
|
||||
else:
|
||||
self.position = blobby.global_position
|
||||
@ -89,8 +91,13 @@ 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 ||
|
||||
left_edge_pos + target_offset.x - 24 < limit_left ||
|
||||
right_edge_pos + target_offset.x + 24 > limit_right ):
|
||||
return
|
||||
if(sign(velocity.x) < 0):
|
||||
offset_track = shiftLeft.find_track(".:offset")
|
||||
shiftLeft.track_set_key_value(offset_track, 0, offset)
|
||||
@ -114,8 +121,10 @@ func _adapt_to_movement(velocity: Vector2) -> void:
|
||||
print("shiftright")
|
||||
anim_player.play("shiftingRight")
|
||||
elif(slow_time >= offset_reset_seconds && !anim_player.is_playing()):
|
||||
if(left_edge_pos > limit_left && limit_right > right_edge_pos):
|
||||
target_offset.x = 0
|
||||
if(offset == target_offset):
|
||||
return
|
||||
if(left_edge_pos > limit_left && limit_right > right_edge_pos):
|
||||
offset_track = shiftCenter.find_track(".:offset")
|
||||
shiftCenter.track_set_key_value(offset_track, 0, offset)
|
||||
shiftCenter.track_set_key_value(offset_track, 1, target_offset)
|
||||
@ -133,8 +142,7 @@ func _adapt_to_movement(velocity: Vector2) -> void:
|
||||
shiftCenter.track_set_key_value(limit_bottom_track, 1, original_limit_bottom)
|
||||
print("shiftcenter")
|
||||
anim_player.play("shiftingCenter")
|
||||
# reset_limits()
|
||||
position = blobby.position
|
||||
return
|
||||
|
||||
func reset_limits() -> void:
|
||||
limit_left = original_limit_left
|
||||
|
||||
@ -631,9 +631,10 @@ texture = ExtResource( 8 )
|
||||
[node name="AnimatedSprite" type="AnimatedSprite" parent="ParallaxBackground/ParallaxLayer5"]
|
||||
visible = false
|
||||
frames = SubResource( 7 )
|
||||
frame = 9
|
||||
frame = 4
|
||||
playing = true
|
||||
|
||||
[node name="AnimatedSprite2" type="AnimatedSprite" parent="ParallaxBackground/ParallaxLayer5"]
|
||||
frames = SubResource( 8 )
|
||||
frame = 9
|
||||
playing = true
|
||||
|
||||
Loading…
Reference in New Issue
Block a user