Fixed head vertical rotation so your head no longer can do flips
This commit is contained in:
@ -3,21 +3,21 @@ extends Node3D
|
|||||||
@export var vertical_joystick_sensitity : float = 2
|
@export var vertical_joystick_sensitity : float = 2
|
||||||
@export var vertical_mouse_sensitivity : float = 0.02
|
@export var vertical_mouse_sensitivity : float = 0.02
|
||||||
|
|
||||||
func can_look(amount, sensitivity):
|
var max_angle_radians = 1.5
|
||||||
var current_rotation_x = global_rotation_degrees.x
|
|
||||||
var amount_to_move = amount * vertical_mouse_sensitivity
|
|
||||||
var angle_after_move = current_rotation_x + amount_to_move
|
|
||||||
if angle_after_move >= -85 and angle_after_move <= 85:
|
|
||||||
return true
|
|
||||||
else:
|
|
||||||
false
|
|
||||||
|
|
||||||
func _process(delta):
|
func _process(delta):
|
||||||
var look_velocity = Input.get_vector("look_left", "look_right", "look_up", "look_down")
|
var look_velocity = Input.get_vector("look_left", "look_right", "look_up", "look_down")
|
||||||
rotate_x(-look_velocity.y * vertical_joystick_sensitity * delta)
|
var rotate_degree = -look_velocity.y * vertical_joystick_sensitity
|
||||||
|
rotate_x(rotate_degree)
|
||||||
|
|
||||||
|
|
||||||
func _unhandled_input(event):
|
func _unhandled_input(event):
|
||||||
if event is InputEventMouseMotion:
|
if event is InputEventMouseMotion:
|
||||||
var rotate_amount = -event.relative.y * vertical_mouse_sensitivity
|
var mouse_movement = -event.relative.y
|
||||||
self.rotate_x(rotate_amount)
|
var rotate_amount = mouse_movement * vertical_mouse_sensitivity
|
||||||
|
var rotation_after = rotate_amount + rotation.x
|
||||||
|
if rotation_after <= max_angle_radians and rotate_amount > 0:
|
||||||
|
rotate_x(rotate_amount)
|
||||||
|
elif rotation_after >= -max_angle_radians and rotate_amount < 0:
|
||||||
|
rotate_x(rotate_amount)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user