Advertisement
chris33556

jump_animation_test

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