correct issue rotate after multi loop

This commit is contained in:
AleaJactaEst 2022-02-03 13:44:16 +01:00
parent 553741deef
commit 2eb384b920

View file

@ -13,6 +13,7 @@ var speed_rotate_1sec = PI
var max_angle = PI / 2 var max_angle = PI / 2
const TWO_PI = 2.0 * PI const TWO_PI = 2.0 * PI
const PI_2 = PI / 2.0 const PI_2 = PI / 2.0
var debug:bool = false
func _init(): func _init():
@ -31,6 +32,12 @@ func _input(event):
Input.set_mouse_mode(Input.MOUSE_MODE_HIDDEN) Input.set_mouse_mode(Input.MOUSE_MODE_HIDDEN)
elif Input.is_action_just_released ( "ui_strafe" ): elif Input.is_action_just_released ( "ui_strafe" ):
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE) Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
if Input.is_action_just_released("ui_cut"):
print("debug on")
debug = true
if Input.is_action_just_released("ui_copy"):
print("debug off")
debug = false
if Input.is_mouse_button_pressed( 2 ): if Input.is_mouse_button_pressed( 2 ):
if event is InputEventMouseMotion: if event is InputEventMouseMotion:
@ -65,7 +72,7 @@ func _physics_process(delta):
if y != 0: if y != 0:
var dt = y * delta * speed_rotate_1sec var dt = y * delta * speed_rotate_1sec
camera_rotate_y += dt camera_rotate_y += dt
if camera_rotate_y >= PI: if camera_rotate_y > PI:
camera_rotate_y -= TWO_PI camera_rotate_y -= TWO_PI
elif camera_rotate_y <= -PI: elif camera_rotate_y <= -PI:
camera_rotate_y += TWO_PI camera_rotate_y += TWO_PI
@ -73,9 +80,11 @@ func _physics_process(delta):
# Get the input direction and handle the movement/deceleration. # Get the input direction and handle the movement/deceleration.
# As good practice, you should replace UI actions with custom gameplay actions. # As good practice, you should replace UI actions with custom gameplay actions.
var input_dir = Input.get_vector("ui_strafe_right", "ui_strafe_left", "ui_down", "ui_up") var input_dir: Vector2
if Input.is_action_pressed("ui_strafe"): if Input.is_action_pressed("ui_strafe"):
input_dir = Input.get_vector("ui_right", "ui_left", "ui_down", "ui_up") input_dir = Input.get_vector("ui_right", "ui_left", "ui_down", "ui_up")
else:
input_dir = Input.get_vector("ui_strafe_right", "ui_strafe_left", "ui_down", "ui_up")
var direction = (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized() var direction = (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
if direction: if direction:
motion_velocity.x = direction.x * SPEED motion_velocity.x = direction.x * SPEED
@ -87,6 +96,8 @@ func _physics_process(delta):
move_and_slide() move_and_slide()
func _process( delta ): func _process( delta ):
if debug:
print(camera_rotate_y,", ", player_rotate_y)
var diff = camera_rotate_y - player_rotate_y var diff = camera_rotate_y - player_rotate_y
if diff > PI: if diff > PI:
@ -101,7 +112,6 @@ func _process( delta ):
if absdiff <= 0.5 * delta: if absdiff <= 0.5 * delta:
rotate_y( diff ) rotate_y( diff )
$camera_root/horizontal_root.rotate_y( -diff ) $camera_root/horizontal_root.rotate_y( -diff )
# $Mesh/character.rotate_y( diff )
player_rotate_y = camera_rotate_y player_rotate_y = camera_rotate_y
else: else:
if diff >= 0.0: if diff >= 0.0:
@ -110,5 +120,8 @@ func _process( delta ):
diff = -delta * speed_rotate_1sec diff = -delta * speed_rotate_1sec
rotate_y( diff ) rotate_y( diff )
$camera_root/horizontal_root.rotate_y( -diff ) $camera_root/horizontal_root.rotate_y( -diff )
#$Mesh/character.rotate_y( diff )
player_rotate_y += diff player_rotate_y += diff
if player_rotate_y > PI:
player_rotate_y -= TWO_PI
elif player_rotate_y <= -PI:
player_rotate_y += TWO_PI