Advertisement
chris33556

player basic movement

Jan 6th, 2023
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. extends KinematicBody
  2.  
  3. onready var animatedSprite = $AnimatedSprite3D
  4. var isAttacking = false
  5. var movement = Vector3(0, 0, 0)
  6. var speed = 150
  7. export (int) var damage := 10
  8.  
  9. func _process(delta):
  10. var input_vector = Vector3.ZERO
  11. input_vector.x = Input.get_action_strength("ui_right") - Input.get_action_strength("ui_left")
  12. input_vector.z = Input.get_action_strength("ui_up") - Input.get_action_strength("ui_down")
  13. input_vector = input_vector.normalized()
  14.  
  15. if input_vector != Vector3.ZERO:
  16. movement.x = input_vector.x * speed
  17. movement.z = input_vector.z * -speed
  18. $AnimatedSprite3D.play("walk")
  19. isAttacking = false
  20.  
  21.  
  22. else:
  23. if $AnimatedSprite3D.animation == "punch" and $AnimatedSprite3D.frame !=2:
  24. pass
  25. else:
  26. movement.x = 0
  27. movement.z = 0
  28. $AnimatedSprite3D.play("idle")
  29. isAttacking == false
  30. $attackArea/CollisionShape.disabled = true
  31.  
  32.  
  33.  
  34. if Input.is_action_just_pressed("attack"):
  35. $AnimatedSprite3D.play("punch")
  36. $attackArea/CollisionShape.disabled = false
  37. isAttacking = true
  38.  
  39.  
  40. if movement.x > 0:
  41. animatedSprite.flip_h = false
  42. scale.x = 1
  43. elif movement.x < 0:
  44. animatedSprite.flip_h = false
  45. scale.x = -1
  46.  
  47.  
  48. movement = move_and_slide(movement * delta)
  49.  
  50.  
  51.  
  52. #func _on_AnimatedSprite3D_animation_finished():
  53. # if $AnimatedSprite3D.play("punch"):
  54. # isAttacking = false
  55.  
  56.  
  57.  
  58.  
  59. func _on_attackArea_body_entered(body):
  60. if body.has_method("handle_hit"):
  61. body.handle_hit(damage)
  62.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement