Advertisement
chris33556

crouch & jump script attempt

Oct 28th, 2022
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 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 = jump_impulse
  65. AnimSprite.play("crouching")
  66. isAttacking = false
  67. else:
  68. if not is_on_floor():
  69. AnimSprite.play("jumping")
  70.  
  71. velocity = move_and_slide(velocity, Vector3.UP)
  72.  
  73. return velocity.normalized()
  74.  
  75. func apply_gravity():
  76. velocity.y = velocity.y + gravity
  77.  
  78.  
  79.  
  80.  
  81.  
  82. func _on_AnimatedSprite3D_animation_finished():
  83. if $AnimatedSprite3D.animation == "punch":
  84. $AttackArea/CollisionShape.disabled = true
  85. isAttacking = false
  86.  
  87. if $AnimatedSprite3D.animation == "reverse_kick":
  88. $AttackArea/CollisionShape.disabled = true
  89. isAttacking = false
  90.  
  91.  
  92.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement