Implement movement smoothing on Player entity

This commit is contained in:
Squinty 2024-04-19 22:02:37 +00:00
parent 7f593d2134
commit d349c440e4
11 changed files with 587 additions and 77 deletions

View file

@ -30,11 +30,11 @@ extends Control
func _ready() -> void:
_player_name_label.text = player.name
func _process(_delta : float) -> void:
# retrieve camera for current viewport
var camera : Camera3D = get_viewport().get_camera_3d()
# if the player is NOT infront of the camera or camera does NOT have LOS to player
if camera.is_position_behind(attach_point.global_position) or !is_within_los:
_iff_container.hide() # hide the IFF and exit function
@ -60,21 +60,21 @@ func _physics_process(_delta : float) -> void:
var new_iff_position : Vector2 = camera.unproject_position(attach_point.global_position) # get the screen location of the players head
var viewport_size : Vector2 = get_viewport_rect().size
# check if the unprojected point lies inside the viewport
if !Rect2(Vector2(0, 0), viewport_size).has_point(new_iff_position):
_iff_container.hide() # hide the IFF and exit function
return
# if player is NOT in range to have its healthbar and name drawn
if (new_iff_position - viewport_size / 2).length() > iff_in_range_radius_ratio * viewport_size.length():
_iff_in_range_container.hide() # hide the in range IFF
else:
_iff_in_range_container.show()
new_iff_position.y -= _iff_container.size.y # move the IFF up so the bottom of it is at the players head
new_iff_position.x -= _iff_container.size.x / 2 # move the IFF left so it's centered horizontally above players head
position = new_iff_position # set the position of the IFF
func _update_health_bar(health : float) -> void:
@ -86,6 +86,6 @@ func _update_health_bar(health : float) -> void:
healthbar_fill_stylebox.bg_color = healthbar_low_health_color
else:
healthbar_fill_stylebox.bg_color = healthbar_high_health_color
func _on_health_changed(new_health : float) -> void:
_update_health_bar(new_health)