Camera pan fix
This commit is contained in:
parent
699bdaed45
commit
c8cbd72029
|
@ -32,22 +32,26 @@ var looking_right := true
|
||||||
func _ready():
|
func _ready():
|
||||||
if follow_camera != null:
|
if follow_camera != null:
|
||||||
camera_stack.append(follow_camera)
|
camera_stack.append(follow_camera)
|
||||||
|
var apply_reset = func(): camera_transition_time_tmp = 0.0
|
||||||
|
apply_reset.call_deferred()
|
||||||
|
|
||||||
|
|
||||||
func _physics_process(delta: float):
|
func _physics_process(delta: float):
|
||||||
if look_aside_enabled:
|
if look_aside_enabled:
|
||||||
var pos_target = look_aside if looking_right else - look_aside
|
var pos_target = look_aside if looking_right else - look_aside
|
||||||
var curve_x = abs(pos_target - position.x) / (look_aside * 2)
|
var curve_x = abs(pos_target - position.x) / (look_aside * 2)
|
||||||
print("posx: ", position.x)
|
|
||||||
print("postarget: ", pos_target)
|
|
||||||
print(curve_x)
|
|
||||||
position.x += sign(pos_target) * look_aside_speed_curve.sample(
|
position.x += sign(pos_target) * look_aside_speed_curve.sample(
|
||||||
curve_x) * delta
|
curve_x) * delta
|
||||||
position.x = clamp(position.x, -look_aside, look_aside)
|
position.x = clamp(position.x, -look_aside, look_aside)
|
||||||
|
|
||||||
# Camera updates
|
# Camera position update
|
||||||
camera_transition_time_tmp -= delta
|
camera_transition_time_tmp -= delta
|
||||||
if camera_transition_time_tmp <= 0.0:
|
if camera_transition_time_tmp <= 0.0:
|
||||||
camera_transition_time_tmp = 0.0
|
camera_transition_time_tmp = 0.0
|
||||||
|
|
||||||
|
update_camera_properties()
|
||||||
|
|
||||||
|
func update_camera_properties():
|
||||||
if !camera_stack.is_empty():
|
if !camera_stack.is_empty():
|
||||||
# Position interpolation
|
# Position interpolation
|
||||||
var target_pos = try_inherit("inherit_position", "global_position")
|
var target_pos = try_inherit("inherit_position", "global_position")
|
||||||
|
@ -55,13 +59,13 @@ func _physics_process(delta: float):
|
||||||
camera_original_position \
|
camera_original_position \
|
||||||
+ transition_speed_curve.sample(1.0 - camera_transition_time_tmp) \
|
+ transition_speed_curve.sample(1.0 - camera_transition_time_tmp) \
|
||||||
* (target_pos - camera_original_position)
|
* (target_pos - camera_original_position)
|
||||||
|
|
||||||
# Limits
|
# Limits
|
||||||
limit_left = try_inherit("inherit_limit", "limit_left")
|
limit_left = try_inherit("inherit_limit", "limit_left")
|
||||||
limit_right = try_inherit("inherit_limit", "limit_right")
|
limit_right = try_inherit("inherit_limit", "limit_right")
|
||||||
limit_top = try_inherit("inherit_limit", "limit_top")
|
limit_top = try_inherit("inherit_limit", "limit_top")
|
||||||
limit_bottom = try_inherit("inherit_limit", "limit_bottom")
|
limit_bottom = try_inherit("inherit_limit", "limit_bottom")
|
||||||
|
|
||||||
|
|
||||||
func apply_camera(c):
|
func apply_camera(c):
|
||||||
if camera_stack.find(c) == -1:
|
if camera_stack.find(c) == -1:
|
||||||
camera_stack.append(c)
|
camera_stack.append(c)
|
||||||
|
|
Loading…
Reference in a new issue