Advertisement
Ragdev

Headbob script

Apr 16th, 2024 (edited)
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. extends CharacterBody3D
  2.  
  3. const BOB_FREQ = 1.5
  4. const BOB_AMP = 0.04
  5. var t_bob = 0.0
  6.  
  7. func _process(delta):
  8.     t_bob += delta * velocity.length() * float(is_on_floor())
  9.     camera.transform.origin = headbob(t_bob)
  10.  
  11. func headbob(time) -> Vector3:
  12.     var pos = Vector3.ZERO
  13.     pos.y = sin(time * BOB_FREQ) * BOB_AMP
  14.     pos.x = cos(time * BOB_FREQ / 2) * BOB_AMP
  15.     return pos
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement