correct issue rotate after multi loop
This commit is contained in:
parent
553741deef
commit
2eb384b920
1 changed files with 17 additions and 4 deletions
|
@ -13,6 +13,7 @@ var speed_rotate_1sec = PI
|
|||
var max_angle = PI / 2
|
||||
const TWO_PI = 2.0 * PI
|
||||
const PI_2 = PI / 2.0
|
||||
var debug:bool = false
|
||||
|
||||
|
||||
func _init():
|
||||
|
@ -31,6 +32,12 @@ func _input(event):
|
|||
Input.set_mouse_mode(Input.MOUSE_MODE_HIDDEN)
|
||||
elif Input.is_action_just_released ( "ui_strafe" ):
|
||||
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 event is InputEventMouseMotion:
|
||||
|
@ -65,7 +72,7 @@ func _physics_process(delta):
|
|||
if y != 0:
|
||||
var dt = y * delta * speed_rotate_1sec
|
||||
camera_rotate_y += dt
|
||||
if camera_rotate_y >= PI:
|
||||
if camera_rotate_y > PI:
|
||||
camera_rotate_y -= TWO_PI
|
||||
elif camera_rotate_y <= -PI:
|
||||
camera_rotate_y += TWO_PI
|
||||
|
@ -73,9 +80,11 @@ func _physics_process(delta):
|
|||
|
||||
# Get the input direction and handle the movement/deceleration.
|
||||
# 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"):
|
||||
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()
|
||||
if direction:
|
||||
motion_velocity.x = direction.x * SPEED
|
||||
|
@ -87,6 +96,8 @@ func _physics_process(delta):
|
|||
move_and_slide()
|
||||
|
||||
func _process( delta ):
|
||||
if debug:
|
||||
print(camera_rotate_y,", ", player_rotate_y)
|
||||
var diff = camera_rotate_y - player_rotate_y
|
||||
|
||||
if diff > PI:
|
||||
|
@ -101,7 +112,6 @@ func _process( delta ):
|
|||
if absdiff <= 0.5 * delta:
|
||||
rotate_y( diff )
|
||||
$camera_root/horizontal_root.rotate_y( -diff )
|
||||
# $Mesh/character.rotate_y( diff )
|
||||
player_rotate_y = camera_rotate_y
|
||||
else:
|
||||
if diff >= 0.0:
|
||||
|
@ -110,5 +120,8 @@ func _process( delta ):
|
|||
diff = -delta * speed_rotate_1sec
|
||||
rotate_y( diff )
|
||||
$camera_root/horizontal_root.rotate_y( -diff )
|
||||
#$Mesh/character.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
|
||||
|
|
Loading…
Reference in a new issue