Still trying.

This commit is contained in:
Dustin 2025-04-02 00:55:19 -07:00
parent 29ca00a8a0
commit 72f5fb64dc
2 changed files with 15 additions and 11 deletions

View File

@ -29,14 +29,12 @@ extents = Vector2( 160, 90 )
[node name="ViewportContainer" type="ViewportContainer" parent="."]
material = SubResource( 3 )
margin_left = -2.0
margin_top = -2.0
margin_right = 320.0
margin_bottom = 180.0
rect_scale = Vector2( 2, 2 )
[node name="Viewport" type="Viewport" parent="ViewportContainer"]
size = Vector2( 322, 182 )
size = Vector2( 320, 180 )
handle_input_locally = false
render_target_update_mode = 3

View File

@ -19,14 +19,18 @@ func _ready():
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
#var tracking_pos = PlayerInfo.player_position
var tracking_pos = _tracking_node.global_position
# var tracking_pos = lerp(global_position, _tracking_node.global_position , 0.7)
var tracking_pos = _tracking_node.global_position.round()
actual_cam_pos = lerp(position, tracking_pos, delta * 3)
#position = actual_cam_pos.round()
position = actual_cam_pos
var cam_subpixel_pos = actual_cam_pos.round() - position
# actual_cam_pos = lerp(actual_cam_pos, tracking_pos, delta * 5)
actual_cam_pos = lerp(actual_cam_pos, tracking_pos, delta * 5)
#position = actual_cam_pos
var cam_subpixel_pos = actual_cam_pos.round() - actual_cam_pos
# LevelInfo.viewport_container.material.set_shader_param("cam_offset", cam_subpixel_pos )
global_position = actual_cam_pos.round()
LevelInfo.viewport_container.material.set_shader_param("cam_offset", cam_subpixel_pos )
UiManager.debug_text = ("SP: " + str(cam_subpixel_pos.snapped(Vector2(0.01,0.01))) +
"\nCP: " + str (position.snapped(Vector2(0.01,0.01))) +
@ -40,9 +44,11 @@ func _process(delta):
# # Then substract half of the game size and add the player position
#
# var mouse_pos = _global.viewport.get_mouse_position() / window_scale - (game_size/2) + player.global_position
# # Use another lerp to make the movement smooth
# actual_cam_pos = lerp(actual_cam_pos, cam_pos, 5*delta)
# # Using a lerp, the cameras position is moved towards the mouse position
# var cam_pos = lerp( player.global_position, mouse_pos, 0.7)
#
# # Use another lerp to make the movement smooth
# actual_cam_pos = lerp(actual_cam_pos, cam_pos, 5*delta)#
# # Calculate the "subpixel" position of the new camera position
# var cam_subpixel_pos = actual_cam_pos.round() - actual_cam_pos
#