Advertisement
chris33556

lance_script_updated_24_12_22

Dec 24th, 2022
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.45 KB | None | 0 0
  1. extends KinematicBody
  2.  
  3. onready var AnimSprite = $AnimatedSprite3D
  4. var velocity = Vector3(0, 0, 0)
  5. var speed = 70
  6. var SpeedStop = 0
  7. var isAttacking = false
  8. var isJumping = false
  9. var gravity = -10
  10. var jump_impulse = 200
  11. var canPick = true
  12. onready var AttackArea = $AttackArea
  13. export (int) var damage := 10
  14.  
  15.  
  16. func _process(delta):
  17. $"../Camera".global_transform.origin.x = global_transform.origin.x
  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. $snapPunch.play()
  31. velocity.x = 0
  32. velocity.z = 0
  33. speed = 0
  34. $AnimatedSprite3D.play("punch")
  35. $AnimatedSprite3D/AttackArea/CollisionPunch.disabled = false
  36. isAttacking = true
  37. elif isAttacking == false:
  38. speed = 70
  39.  
  40.  
  41.  
  42. # elif Input.is_action_just_pressed("crouch"):
  43. # velocity.x = 0
  44. # velocity.z = 0
  45. # $AnimatedSprite3D.play("crouching")
  46. # isJumping = false
  47.  
  48. if Input.is_action_just_pressed("reverse_kick"):
  49. $snapPunch.play()
  50. velocity.x = 0
  51. velocity.z = 0
  52. $AnimatedSprite3D.play("reverse_kick")
  53. $AnimatedSprite3D/AttackArea/CollisionRearKick.disabled = false
  54. isAttacking = true
  55.  
  56.  
  57.  
  58. else:
  59. if not is_on_floor():
  60. velocity.y -= gravity * delta
  61. # if Input.is_action_pressed("ui_right"):
  62. velocity.z = 0
  63. isAttacking = false
  64.  
  65. if velocity.x > 0:
  66. AnimSprite.scale.x = 1
  67. elif velocity.x < 0:
  68. AnimSprite.scale.x = -1
  69.  
  70.  
  71. func _is_on_floor():
  72. if Input.is_action_just_pressed("PickUp"):
  73. $AnimatedSprite3D.play("pick_up")
  74. velocity.x = 0
  75. velocity.z = 0
  76. isAttacking = true
  77.  
  78.  
  79. if Input.is_action_just_pressed("jump") and is_on_floor():
  80. velocity.y = jump_impulse
  81. AnimSprite.play("jumping")
  82. $snapPunch.play()
  83. $AnimatedSprite3D/AttackArea/CollisionAirPunch.disabled = true
  84. isAttacking = false
  85.  
  86.  
  87. elif Input.is_action_just_pressed("airAttack") and not is_on_floor():
  88. $AnimatedSprite3D.play("air_attack")
  89. $snapPunch.play()
  90. $AnimatedSprite3D/AttackArea/CollisionAirPunch.disabled = false
  91. isAttacking = true
  92.  
  93. if Input.is_action_pressed("move_down") and Input.is_action_pressed("KneeAttack"):
  94. $AnimatedSprite3D.play("KneeAttack")
  95. $snapPunch.play()
  96. $AnimatedSprite3D/AttackArea/CollisionAirPunch.disabled = false
  97. isAttacking = true
  98.  
  99. elif is_on_floor():
  100. $AnimatedSprite3D/AttackArea/CollisionAirPunch.disabled = true
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107. velocity = move_and_slide(velocity, Vector3.UP)
  108.  
  109. return velocity.normalized()
  110.  
  111. func apply_gravity():
  112. velocity.y = velocity.y + gravity
  113.  
  114.  
  115.  
  116.  
  117.  
  118. func _on_AnimatedSprite3D_animation_finished():
  119. if $AnimatedSprite3D.animation == "punch":
  120. $AnimatedSprite3D/AttackArea/CollisionPunch.disabled = true
  121. isAttacking = false
  122.  
  123. if $AnimatedSprite3D.animation == "reverse_kick":
  124. $AnimatedSprite3D/AttackArea/CollisionRearKick.disabled = true
  125. isAttacking = false
  126.  
  127. if $AnimatedSprite3D.animation == "pick_up":
  128. isAttacking = false
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135. func _on_AttackArea_body_entered(body):
  136. if body.has_method("handle_hit"):
  137. body.handle_hit(damage)
  138.  
  139.  
  140. func _on_Area_area_entered(area):
  141. print(area.name, "entered")
  142.  
  143.  
  144. func _on_Area_area_exited(area):
  145. print(area.name, "exited")
  146.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement