Advertisement
chris33556

BASIC_walk_punch_sample

Sep 22nd, 2022
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 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. var canMove = false
  15.  
  16. var timer = null
  17. var crouch_delay = 0.5
  18. var isCrouch = true
  19. var current_animation
  20.  
  21.  
  22.  
  23. func _process(delta):
  24. if $AnimatedSprite3D.animation == "punch" and $AnimatedSprite3D.frame !=2:
  25. return
  26.  
  27.  
  28.  
  29. input_vector.x = Input.get_action_strength("move_right") - Input.get_action_strength("move_left")
  30. input_vector.z = Input.get_action_strength("move_up") - Input.get_action_strength("move_down")
  31. input_vector = input_vector.normalized()
  32.  
  33.  
  34. if input_vector != Vector3.ZERO && canMove:
  35. velocity.x = input_vector.x * speed
  36. velocity.z = input_vector.z * -speed
  37. AnimSprite.play("walk")
  38.  
  39. else:
  40. velocity.x = 0
  41. velocity.z = 0
  42. AnimSprite.play("idle")
  43.  
  44.  
  45.  
  46. if Input.is_action_just_pressed("punch") : #and isWalking:
  47. $AnimatedSprite3D.play("punch")
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61. if velocity.x > 0:
  62. AnimSprite.flip_h = false
  63. scale.x = 29
  64. elif velocity.x < 0:
  65. AnimSprite.flip_h = false
  66. scale.x = -29
  67.  
  68.  
  69.  
  70. velocity = move_and_slide(velocity)
  71.  
  72. return velocity.normalized()
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement