Advertisement
chris33556

character script

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