correct move camera left/right
This commit is contained in:
parent
5a310fb4e2
commit
9378a272d7
1 changed files with 35 additions and 7 deletions
|
@ -66,6 +66,7 @@ var player_rotate_y = 0.0
|
|||
var player_rotate_x = 0.0
|
||||
# Activate reconciliation between camera & player
|
||||
var reconciliate_rotate_camera_player:bool = false
|
||||
var move_camera_back_player:bool = false
|
||||
# Player run
|
||||
var is_run:bool = false
|
||||
var zoom:float = ZOOM_DEFAULT
|
||||
|
@ -596,6 +597,10 @@ func loop_collision_y(col:RayCast3D, maxloop:int, angle_y:float ):
|
|||
col.force_raycast_update()
|
||||
if not col.is_colliding():
|
||||
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:
|
||||
new_camera_rotate_y = camera_rotate_y + angle_y
|
||||
if new_camera_rotate_y > PI:
|
||||
|
@ -684,12 +689,14 @@ func detect_camera_collision_y(angle_y):
|
|||
loop_collision_y(coll, 20, +0.01 )
|
||||
|
||||
|
||||
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)
|
||||
func rotate_camera_y(angle_y):
|
||||
var coll:RayCast3D
|
||||
if angle_y >= 0.0:
|
||||
coll = $camera_root/horizontal_root/vertical_root/Camera3D_TPS/Right
|
||||
else:
|
||||
coll = $camera_root/horizontal_root/vertical_root/Camera3D_TPS/Left
|
||||
if coll.is_colliding():
|
||||
return
|
||||
camera_rotate_y -= angle_y
|
||||
if camera_rotate_y > PI:
|
||||
camera_rotate_y -= TAU
|
||||
|
@ -699,6 +706,15 @@ func move_camera(angle_x, 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):
|
||||
var posTarget:Vector3 = $camera_root.get_position()
|
||||
if delta_y >= 0.0:
|
||||
|
@ -876,7 +892,19 @@ func _process( delta ):
|
|||
player_rotate_y -= TAU
|
||||
elif player_rotate_y <= -PI:
|
||||
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"):
|
||||
y -= 1
|
||||
if Input.is_action_pressed("INPUT_ACTION_LEFT"):
|
||||
|
|
Loading…
Reference in a new issue