Godot Version
Godot4.5
Question
(sorry for bad english in advance)
I’m new to godot, so i did what every newbie does and searched guides to help me . one of the things that i found trouble in, is making a fighting game 3d camera that functions like in street fighter 4~6. and the only video that i found that talks about this subject matter is this one. while it functions it has the minor bug of the z position going back and forth, making the camera zoom in and out
my only good guess as to why this happens is that adding movement_speed variable to the z position makes it so the current proportion smaller than the initial one in the following frame, triggering the elif statement and the subtraction happens returning the current proportion value to it’s initial state and triggering the if statement in the following frame. here is the code (ignore the prints those are for debugging) :
func calculate_position(rect: Rect2, unprojected_rect: Rect2) -> Vector3:
var center : = calculate_center(rect)
if initial_proportion == 0 or initial_distance == 0:
initial_proportion = unprojected_rect.size.x / viewport_rect.size.x
initial_distance = position.distance_to(get_child(0).position)
var z_position : = position.z
if unprojected_rect.size.x / viewport_rect.size.x > initial_proportion:
z_position = position.z + move_speed
print("t1")
print(unprojected_rect.size.x / viewport_rect.size.x > initial_proportion)
print(unprojected_rect.size.x / viewport_rect.size.x )
print( initial_proportion)
elif unprojected_rect.size.x / viewport_rect.size.x < initial_proportion and z_position > initial_distance:
z_position = position.z -move_speed
print("t2")
print(unprojected_rect.size.x / viewport_rect.size.x < initial_proportion and z_position > initial_distance)
print(unprojected_rect.size.x / viewport_rect.size.x )
print( initial_proportion)
return Vector3(center.x + center_offset.x, center.y + center_offset.y, lerp(position.z, z_position, smoothing))
here is debug sample that shows what happens:
