Skip to content

Commit 8e59df1

Browse files
Fix rotation flick: Change rotation func on head bob from vector3 to quaternion
1 parent 2307965 commit 8e59df1

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

fps/bob/head_bob.gd

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ var speed : float = 0
5555
var original_position : Vector3
5656

5757
## Store original rotation of head for headbob reference
58-
var original_rotation : Vector3
58+
var original_rotation : Quaternion
5959

6060
## Actual cycle x of step headbob
6161
var cycle_position_x: float = 0
@@ -69,7 +69,7 @@ var step_interval: float = 0
6969

7070
func _ready():
7171
original_position = head.position
72-
original_rotation = head.rotation
72+
original_rotation = head.quaternion
7373

7474

7575
## Setup bob with bob base interval
@@ -99,7 +99,7 @@ func head_bob_process(horizontal_velocity:Vector3, input_axis:Vector2, is_sprint
9999
new_rotation += _head_bob_rotation(input_axis.y, input_axis.x, _delta)
100100

101101
head.position = new_position
102-
head.rotation = new_rotation
102+
head.quaternion = new_rotation
103103

104104

105105
## Apply headbob jump
@@ -114,9 +114,10 @@ func reset_cycles():
114114
cycle_position_y = 0
115115

116116

117-
func _head_bob_rotation(x, z, _delta) -> Vector3:
118-
var target_rotation = Vector3(x * angle_limit_for_rotation, 0.0, -z * angle_limit_for_rotation)
119-
return lerp(head.rotation, target_rotation, speed_rotation * _delta)
117+
func _head_bob_rotation(x, z, _delta) -> Quaternion:
118+
var target_rotation : Quaternion
119+
target_rotation.from_euler(Vector3(x * angle_limit_for_rotation, 0.0, -z * angle_limit_for_rotation))
120+
return lerp(head.quaternion, target_rotation, speed_rotation * _delta)
120121

121122

122123
func _do_head_bob(speed: float, delta: float) -> Vector3:

0 commit comments

Comments
 (0)