Advertisement
Guest User

Untitled

a guest
Nov 12th, 2022
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.70 KB | None | 0 0
  1. extends KinematicBody
  2.  
  3.  
  4. var speed = 15.0
  5. var jump_str = 25.0
  6. var gravity = 50.0
  7.  
  8. var vel = Vector3.ZERO
  9. var snap_vect = Vector3.DOWN
  10. var dir = Vector3.ZERO
  11.  
  12. onready var _spr_arm = $SpringArm
  13. onready var _model = $woman#$girl
  14.  
  15. var is_spinning = false
  16. var spin_angle = 0
  17. var look_angle = 0
  18. var look_dir = Vector2()
  19.  
  20.  
  21.  
  22. func _physics_process(delta):
  23. dir = Vector3.ZERO
  24.  
  25. dir.x = Input.get_action_strength("D") - Input.get_action_strength("A")
  26. dir.z = Input.get_action_strength("S") - Input.get_action_strength("W")
  27. dir = dir.rotated(Vector3.UP, _spr_arm.rotation.y).normalized()
  28.  
  29.  
  30. vel.x = dir.x * speed
  31. vel.z = dir.z * speed
  32. vel.y -= gravity * delta
  33.  
  34.  
  35.  
  36. # Jump
  37.  
  38. var just_landed = is_on_floor() and snap_vect == Vector3.ZERO
  39. var is_jumping = is_on_floor() and Input.is_action_just_pressed("JUMP")
  40.  
  41. if is_jumping:
  42. vel.y = jump_str
  43. snap_vect = Vector3.ZERO
  44.  
  45. elif just_landed:
  46. snap_vect = Vector3.DOWN
  47.  
  48.  
  49.  
  50. vel = move_and_slide_with_snap(vel, snap_vect, Vector3.UP, true, 4, deg2rad(89))
  51.  
  52.  
  53. # Animations & Facing Direction
  54.  
  55.  
  56.  
  57.  
  58.  
  59. if vel.length() > 0.2:
  60. if not (vel.z == 0 and vel.x == 0):
  61. if not is_spinning:
  62. gravity = 50.0
  63. speed = 15.0
  64.  
  65. look_dir = Vector2(vel.z, vel.x)
  66. _model.rotation.y = look_dir.angle()
  67.  
  68.  
  69. if is_on_floor():
  70. is_spinning = false
  71.  
  72. _model.get_node("AnimationPlayer").playback_speed = 5
  73. _model.get_node("AnimationPlayer").play("Run")
  74.  
  75. else:
  76. _model.get_node("AnimationPlayer").play("Jump")
  77.  
  78. if is_spinning:
  79. _model.rotation.y += 50 * delta
  80.  
  81.  
  82. else:
  83. gravity = 25.0
  84. speed = 30.0
  85.  
  86. _model.rotation.y += 50 * delta
  87. _model.get_node("AnimationPlayer").play("0TPose")
  88.  
  89.  
  90. if is_on_floor():
  91. is_spinning = false
  92. gravity = 30.0
  93. speed = 25.0
  94.  
  95. _model.get_node("AnimationPlayer").playback_speed = 5
  96. _model.get_node("AnimationPlayer").play("Run")
  97.  
  98. else:
  99. _model.get_node("AnimationPlayer").play("Jump")
  100.  
  101. if is_spinning:
  102. _model.rotation.y += 50 * delta
  103.  
  104.  
  105.  
  106. else:
  107. is_spinning = false
  108. gravity = 50.0
  109. speed = 15.0
  110.  
  111.  
  112. else:
  113. is_spinning = false
  114. gravity = 50.0
  115. speed = 15.0
  116.  
  117. if is_on_floor():
  118.  
  119. _model.get_node("AnimationPlayer").playback_speed = 1
  120. _model.get_node("AnimationPlayer").play("Idle")
  121.  
  122. else:
  123. _model.get_node("AnimationPlayer").play("Jump")
  124.  
  125. if is_spinning:
  126. _model.rotation.y += 50 * delta
  127.  
  128.  
  129.  
  130. if translation.y < 1.275 and is_spinning:
  131. translation.y = 1.275
  132.  
  133.  
  134.  
  135.  
  136.  
  137. # warning-ignore:unused_argument
  138. func _process(delta):
  139. _spr_arm.translation = translation
  140.  
  141.  
  142.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement