camera y-panninbg

This commit is contained in:
Rakarake 2025-07-04 16:39:29 +02:00
parent 88ed07d08a
commit 89a16f0f46
4 changed files with 47 additions and 0 deletions

View file

@ -108,6 +108,11 @@ var attack_cooldown_tmp: float
@export var buffer_attack := 0.0
var buffer_attack_tmp := 0.0
## The amount of time it takes for the camera to pan up/down after holding
## digital direction.
@export var y_camera_pan_delay := 0.0
var y_camera_pan_delay_tmp := 0.0
var double_jump_used := false
var dash_used := false
## Not an animation variable (maybe) (perhaps)
@ -138,6 +143,19 @@ func update_looking_right():
looking_right = true
follow_camera.looking_right = looking_right
func update_camera_pan(delta: float):
if current_state() in [run]:
if input_dir.y != 0:
y_camera_pan_delay_tmp -= delta
else:
y_camera_pan_delay_tmp = y_camera_pan_delay
follow_camera.y_camera_pan = 0
follow_camera.y_camera_pan =\
Input.get_action_strength("pan_camera_down") -\
Input.get_action_strength("pan_camera_up")
if y_camera_pan_delay_tmp <= 0:
follow_camera.y_camera_pan = input_dir.y
func _update_input():
if in_control:
var analog := Vector2.ZERO
@ -161,6 +179,7 @@ func _physics_process(delta):
# Looking right (both animation and logic)
if !current_state() in [death]:
update_looking_right()
update_camera_pan(delta)
# Flip player nodes that want to be flipped
for child in self.find_children("*"):
if child.is_in_group("flip_me"):

View file

@ -2887,6 +2887,7 @@ wavedash_x_velocity = 700.0
dashjump_timeframe = 0.15
attack_cooldown = 0.7
buffer_attack = 0.15
y_camera_pan_delay = 0.8
[node name="PlayerCharacterSprite" type="AnimatedSprite2D" parent="."]
sprite_frames = SubResource("SpriteFrames_4lqx6")
@ -2939,6 +2940,8 @@ script = ExtResource("18_kiohe")
look_aside_enabled = true
look_aside = 34.0
look_aside_speed_curve = SubResource("Curve_w1mwi")
y_camera_pan_enabled = true
y_camera_pan_amount = 400.0
inherit_position = true
inherit_limit = true

View file

@ -25,12 +25,21 @@ class_name ExtendedCamera
## the player is facing.
@export
var look_aside := 0.0
## This curve determines the speed of the camera when looking in the opposite direction.
## X: 0-1 the current percentage of distance the camera needs to pan, y: the
## velocity of the camera.
@export
var look_aside_speed_curve: Curve
## Wether camera pan up/down is enabled.
@export
var y_camera_pan_enabled := false
## How much does the camera pan up/down.
@export
var y_camera_pan_amount := 0.0
## Another camera inherits this camera's position when applied (if set).
@export var inherit_position := false
## Another camera inherits this camera's limits (camera bounds) when applied (if set).
@ -53,7 +62,10 @@ const INIT_GRACE_TRANSITION_WINDOW := 0.1
# The time node has spent processing
var time_processing := 0.0
## Set by owner.
var looking_right := true
## Set by owner, expected to be -1.0 to 1.0
var y_camera_pan := 0.0
func _ready():
if follow_camera != null:
@ -71,6 +83,9 @@ func _physics_process(delta: float):
position.x += sign(target_pos) * look_aside_speed_curve.sample(
curve_x) * delta
position.x = clamp(position.x, -look_aside, look_aside)
if y_camera_pan_enabled:
position.y = y_camera_pan_amount * y_camera_pan
# Camera position update
camera_transition_time_tmp -= delta

View file

@ -256,6 +256,16 @@ debug_toggle_dev_camera={
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":67,"key_label":0,"unicode":99,"location":0,"echo":false,"script":null)
]
}
pan_camera_up={
"deadzone": 0.2,
"events": [Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":3,"axis_value":-1.0,"script":null)
]
}
pan_camera_down={
"deadzone": 0.2,
"events": [Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":3,"axis_value":1.0,"script":null)
]
}
[layer_names]