Advertisement
chris33556

punch flip sprite issue

Aug 27th, 2022 (edited)
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. extends KinematicBody
  2.  
  3. onready var AS = $AnimatedSprite3D
  4. var velocity = Vector3()
  5. export var speed = 3
  6. export var gravity = 20
  7. export var jump = 7
  8. var isAttacking = false
  9.  
  10.  
  11.  
  12.  
  13. func _process(delta):
  14. _gravity(delta)
  15. _is_on_floor()
  16. var input_vector = Vector3.ZERO
  17. if is_on_floor():
  18. input_vector.x = Input.get_action_strength("ui_right") - Input.get_action_strength("ui_left")
  19. input_vector.z = Input.get_action_strength("ui_up") - Input.get_action_strength("ui_down")
  20. input_vector = input_vector.normalized()
  21.  
  22.  
  23. if input_vector != Vector3.ZERO:
  24. velocity.x = input_vector.x * speed
  25. velocity.z = input_vector.z * -speed
  26. AS.play("walk")
  27. isAttacking = false
  28.  
  29.  
  30.  
  31.  
  32.  
  33. else:
  34. if not is_on_floor():
  35. velocity.y -= gravity * delta
  36. # if Input.is_action_pressed("ui_right"):
  37. velocity.z = 0
  38. isAttacking = false
  39.  
  40.  
  41.  
  42. else:
  43. velocity.x = 0
  44. velocity.y = 0
  45. AS.play("idle")
  46. isAttacking = false
  47.  
  48.  
  49. if velocity.x > 0:
  50. $AnimatedSprite3D.flip_h = false
  51. scale.x = 1
  52. elif velocity.x < 0:
  53. $AnimatedSprite3D.flip_h = false
  54. scale.x = - 1
  55.  
  56.  
  57.  
  58.  
  59.  
  60. func _gravity(delta):
  61. var input_vector = Vector3.ZERO
  62.  
  63.  
  64. func _is_on_floor():
  65. if Input.is_action_pressed("jump") and is_on_floor():
  66. velocity.y = jump
  67. velocity.z = 0
  68. AS.play("jump")
  69. isAttacking = false
  70.  
  71. velocity = move_and_slide(velocity, Vector3.UP)
  72.  
  73.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement