Advertisement
chris33556

updated beate-em up script 4_9_22

Sep 4th, 2022
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 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. _is_on_floor()
  17. apply_gravity()
  18. if is_on_floor() and not isAttacking:
  19. velocity.x = speed * Input.get_axis("move_left", "move_right")
  20. velocity.z = speed * Input.get_axis("move_up", "move_down")
  21. AnimSprite.play("walk")
  22.  
  23. if velocity.x == 0 and velocity.z == 0:
  24. AnimSprite.play("idle")
  25. isAttacking == false
  26.  
  27. if Input.is_action_just_pressed("punch"):
  28. velocity.x = 0
  29. velocity.z = 0
  30. $AnimatedSprite3D.play("punch")
  31. $AttackArea/CollisionShape.disabled = false
  32. isAttacking = true
  33.  
  34. elif Input.is_action_just_pressed("reverse_kick"):
  35. velocity.x = 0
  36. velocity.z = 0
  37. $AnimatedSprite3D.play("reverse_kick")
  38. isAttacking = true
  39.  
  40. else:
  41. if not is_on_floor():
  42. velocity.y -= gravity * delta
  43. # if Input.is_action_pressed("ui_right"):
  44. velocity.z = 0
  45. isAttacking = false
  46.  
  47. if velocity.x > 0:
  48. AnimSprite.flip_h = false
  49. scale.x = 29
  50. elif velocity.x < 0:
  51. AnimSprite.flip_h = false
  52. scale.x = -29
  53.  
  54. func _is_on_floor():
  55. if Input.is_action_just_pressed("jump") and is_on_floor():
  56. velocity.y = jump_impulse
  57. AnimSprite.play("jumping")
  58. isAttacking = false
  59.  
  60. velocity = move_and_slide(velocity, Vector3.UP)
  61.  
  62. return velocity.normalized()
  63.  
  64. func apply_gravity():
  65. velocity.y = velocity.y + gravity
  66.  
  67.  
  68.  
  69.  
  70.  
  71. func _on_AnimatedSprite3D_animation_finished():
  72. if $AnimatedSprite3D.animation == "punch":
  73. $AttackArea/CollisionShape.disabled = true
  74. isAttacking = false
  75.  
  76. if $AnimatedSprite3D.animation == "reverse_kick":
  77. $AttackArea/CollisionShape.disabled = true
  78. isAttacking = false
  79.  
  80.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement