Advertisement
chris33556

crouch_script

Oct 28th, 2022
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. extends KinematicBody
  2.  
  3. onready var AnimSprite = $AnimatedSprite3D
  4.  
  5. var velocity = Vector3(0, 0, 0)
  6. var speed = 70
  7. var isAttacking = false
  8. var isJumping = false
  9. var gravity = -20
  10. var jump_impulse = 300
  11. onready var AttackArea = $AttackArea
  12. export (int) var damage := 10
  13.  
  14.  
  15. func _process(delta):
  16. if $AnimatedSprite3D.animation == "crouching" and $AnimatedSprite3D.frame !=2:
  17. return
  18. _is_on_floor()
  19. apply_gravity()
  20. if is_on_floor() and not isAttacking:
  21. velocity.x = speed * Input.get_axis("move_left", "move_right")
  22. velocity.z = speed * Input.get_axis("move_up", "move_down")
  23. AnimSprite.play("walk2")
  24.  
  25. if velocity.x == 0 and velocity.z == 0:
  26. AnimSprite.play("idle")
  27. isAttacking == false
  28.  
  29. if Input.is_action_just_pressed("punch"):
  30. velocity.x = 0
  31. velocity.z = 0
  32. $AnimatedSprite3D.play("punch")
  33. $AttackArea/CollisionShape.disabled = false
  34. isAttacking = true
  35.  
  36. # elif Input.is_action_just_pressed("crouch"):
  37. # velocity.x = 0
  38. # velocity.z = 0
  39. # $AnimatedSprite3D.play("crouching")
  40. # isJumping = false
  41.  
  42. elif Input.is_action_just_pressed("reverse_kick"):
  43. velocity.x = 0
  44. velocity.z = 0
  45. $AnimatedSprite3D.play("reverse_kick")
  46. isAttacking = true
  47.  
  48. else:
  49. if not is_on_floor():
  50. velocity.y -= gravity * delta
  51. # if Input.is_action_pressed("ui_right"):
  52. velocity.z = 0
  53. isAttacking = false
  54.  
  55. if velocity.x > 0:
  56. AnimSprite.flip_h = false
  57. scale.x = 29
  58. elif velocity.x < 0:
  59. AnimSprite.flip_h = false
  60. scale.x = -29
  61.  
  62. func _is_on_floor():
  63. if Input.is_action_just_pressed("jump") and is_on_floor():
  64. velocity.y = 0
  65. AnimSprite.play("crouching")
  66. isAttacking = false
  67.  
  68. elif not is_on_floor():
  69.  
  70. AnimSprite.play("jumping")
  71.  
  72. velocity = move_and_slide(velocity, Vector3.UP)
  73.  
  74. return velocity.normalized()
  75.  
  76. func apply_gravity():
  77. velocity.y = velocity.y + gravity
  78.  
  79.  
  80.  
  81.  
  82.  
  83. func _on_AnimatedSprite3D_animation_finished():
  84. if $AnimatedSprite3D.animation == "punch":
  85. $AttackArea/CollisionShape.disabled = true
  86. isAttacking = false
  87.  
  88. if $AnimatedSprite3D.animation == "reverse_kick":
  89. $AttackArea/CollisionShape.disabled = true
  90. isAttacking = false
  91.  
  92.  
  93.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement