chris33556

updated beate-em up script 22_09_22

Sep 22nd, 2022
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.49 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. var input_vector = Vector3.ZERO
  12. onready var AttackArea = $AttackArea
  13. export (int) var damage := 10
  14. var canMove = false
  15.  
  16. var timer = null
  17. var crouch_delay = 0.5
  18. var isCrouch = true
  19. var current_animation
  20.  
  21. func _ready():
  22. timer = Timer.new()
  23. timer.set_one_shot(true)
  24. timer.set_wait_time(crouch_delay)
  25. timer.connect("timeout", self, "on_timeout_complete")
  26. add_child(timer)
  27.  
  28. func on_timeout_complete():
  29. isCrouch = true
  30.  
  31. func _process(delta):
  32. if $AnimatedSprite3D.animation == "punch" and $AnimatedSprite3D.frame !=2:
  33. return
  34.  
  35.  
  36. apply_gravity()
  37. if is_on_floor():
  38. input_vector.x = Input.get_action_strength("move_right") - Input.get_action_strength("move_left")
  39. input_vector.z = Input.get_action_strength("move_up") - Input.get_action_strength("move_down")
  40. input_vector = input_vector.normalized()
  41.  
  42.  
  43. if input_vector != Vector3.ZERO and not canMove:
  44. velocity.x = input_vector.x * speed
  45. velocity.z = input_vector.z * -speed
  46. AnimSprite.play("walk")
  47.  
  48. else:
  49. velocity.x = 0
  50. velocity.z = 0
  51. AnimSprite.play("idle")
  52. isAttacking = false
  53.  
  54.  
  55. if Input.is_action_just_pressed("punch") and not isAttacking: #and isWalking:
  56. $AnimatedSprite3D.play("punch")
  57. $AttackArea/CollisionShape.disabled = false
  58. canMove = true
  59.  
  60.  
  61. if Input.is_action_just_pressed("reverse_kick"):
  62. velocity.x = 0
  63. velocity.z = 0
  64. $AnimatedSprite3D.play("reverse_kick")
  65. isAttacking = true
  66.  
  67. else:
  68. if not is_on_floor():
  69. velocity.y -= gravity * delta
  70. velocity.z = 0
  71. isAttacking = false
  72.  
  73. if Input.is_action_just_pressed("jump") && isCrouch:
  74. velocity.y = 0
  75. AnimSprite.play("crouch")
  76. isCrouch = false
  77.  
  78.  
  79. timer.start()
  80.  
  81.  
  82. if velocity.x > 0:
  83. AnimSprite.flip_h = false
  84. scale.x = 29
  85. elif velocity.x < 0:
  86. AnimSprite.flip_h = false
  87. scale.x = -29
  88.  
  89.  
  90.  
  91. velocity = move_and_slide(velocity, Vector3.UP)
  92.  
  93. return velocity.normalized()
  94.  
  95. func apply_gravity():
  96. velocity.y = velocity.y + gravity
  97.  
  98.  
  99.  
  100.  
  101.  
  102. func _on_AnimatedSprite3D_animation_finished():
  103. if $AnimatedSprite3D.animation == "punch":
  104. $AttackArea/CollisionShape.disabled = true
  105. isAttacking = false
  106.  
  107. if $AnimatedSprite3D.animation == "reverse_kick":
  108. $AttackArea/CollisionShape.disabled = true
  109. isAttacking = false
  110.  
Add Comment
Please, Sign In to add comment