correct move camera left/right

This commit is contained in:
AleaJactaEst 2022-03-28 22:44:44 +02:00
parent 5a310fb4e2
commit 9378a272d7

View file

@ -66,6 +66,7 @@ var player_rotate_y = 0.0
var player_rotate_x = 0.0 var player_rotate_x = 0.0
# Activate reconciliation between camera & player # Activate reconciliation between camera & player
var reconciliate_rotate_camera_player:bool = false var reconciliate_rotate_camera_player:bool = false
var move_camera_back_player:bool = false
# Player run # Player run
var is_run:bool = false var is_run:bool = false
var zoom:float = ZOOM_DEFAULT var zoom:float = ZOOM_DEFAULT
@ -596,6 +597,10 @@ func loop_collision_y(col:RayCast3D, maxloop:int, angle_y:float ):
col.force_raycast_update() col.force_raycast_update()
if not col.is_colliding(): if not col.is_colliding():
return return
if tps:
var diff = camera_rotate_y - player_rotate_y
if diff <= 0.01 and diff >= -0.01:
move_camera_back_player = true
while maxloop > 0: while maxloop > 0:
new_camera_rotate_y = camera_rotate_y + angle_y new_camera_rotate_y = camera_rotate_y + angle_y
if new_camera_rotate_y > PI: if new_camera_rotate_y > PI:
@ -684,12 +689,14 @@ func detect_camera_collision_y(angle_y):
loop_collision_y(coll, 20, +0.01 ) loop_collision_y(coll, 20, +0.01 )
func move_camera(angle_x, angle_y): func rotate_camera_y(angle_y):
var new_camera_rotate_x = camera_rotate_x + angle_x var coll:RayCast3D
if angle_x != 0.0 and new_camera_rotate_x <= PI_2 and new_camera_rotate_x >= - PI_2: if angle_y >= 0.0:
$camera_root/horizontal_root/vertical_root.rotate_x( angle_x ) coll = $camera_root/horizontal_root/vertical_root/Camera3D_TPS/Right
camera_rotate_x = new_camera_rotate_x else:
detect_camera_collision_x(angle_x) coll = $camera_root/horizontal_root/vertical_root/Camera3D_TPS/Left
if coll.is_colliding():
return
camera_rotate_y -= angle_y camera_rotate_y -= angle_y
if camera_rotate_y > PI: if camera_rotate_y > PI:
camera_rotate_y -= TAU camera_rotate_y -= TAU
@ -699,6 +706,15 @@ func move_camera(angle_x, angle_y):
detect_camera_collision_y(-angle_y) detect_camera_collision_y(-angle_y)
func move_camera(angle_x, angle_y):
var new_camera_rotate_x = camera_rotate_x + angle_x
if angle_x != 0.0 and new_camera_rotate_x <= PI_2 and new_camera_rotate_x >= - PI_2:
$camera_root/horizontal_root/vertical_root.rotate_x( angle_x )
camera_rotate_x = new_camera_rotate_x
detect_camera_collision_x(angle_x)
rotate_camera_y(angle_y)
func move_camera_y(delta_y:float): func move_camera_y(delta_y:float):
var posTarget:Vector3 = $camera_root.get_position() var posTarget:Vector3 = $camera_root.get_position()
if delta_y >= 0.0: if delta_y >= 0.0:
@ -876,7 +892,19 @@ func _process( delta ):
player_rotate_y -= TAU player_rotate_y -= TAU
elif player_rotate_y <= -PI: elif player_rotate_y <= -PI:
player_rotate_y += TAU player_rotate_y += TAU
# elif move_camera_back_player:
# var diff:float = camera_rotate_y - player_rotate_y
# var step:float = 0.0
# if diff < 0.0:
# step = +0.1
# else:
# step = -0.1
# rotate_camera_y(step)
# diff = camera_rotate_y - player_rotate_y
# if diff < 0.0:
# diff = -diff
# if diff < 0.01:
# move_camera_back_player = false
if Input.is_action_pressed("INPUT_ACTION_RIGHT"): if Input.is_action_pressed("INPUT_ACTION_RIGHT"):
y -= 1 y -= 1
if Input.is_action_pressed("INPUT_ACTION_LEFT"): if Input.is_action_pressed("INPUT_ACTION_LEFT"):