Advertisement
chris33556

CR2F_updated_on_17_07_2022

Jul 17th, 2022
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. extends KinematicBody
  2.  
  3. onready var animatedSprite = $AnimatedSprite3D
  4.  
  5. var movement = Vector3();
  6. var up = Vector3();
  7. var speed = 70;
  8. var isAttacking = false;
  9. var isJumping = false;
  10. var gravity = -30;
  11. var jump_impulse = 320
  12.  
  13. func _process(delta):
  14. apply_gravity(delta)
  15. #jump()
  16. if Input.is_action_pressed("move_right") && isAttacking == false:
  17. movement.x = speed;
  18. $AnimatedSprite3D.play("walk");
  19. elif Input.is_action_pressed("move_left") && isAttacking == false:
  20. movement.x = -speed;
  21. $AnimatedSprite3D.play("walk");
  22. elif Input.is_action_pressed("move_up") && isAttacking == false:
  23. movement.z = -speed;
  24. $AnimatedSprite3D.play("walk");
  25. elif Input.is_action_pressed("move_down") && isAttacking == false:
  26. movement.z = speed;
  27. $AnimatedSprite3D.play("walk");
  28. else:
  29. movement.x = 0;
  30. movement.z = 0;
  31. if isAttacking == false:
  32. $AnimatedSprite3D.play("idle");
  33.  
  34. if movement.x > 0:
  35. animatedSprite.flip_h = false
  36. elif movement.x < 0:
  37. animatedSprite.flip_h = true
  38.  
  39.  
  40.  
  41. if Input.is_action_just_pressed("reverse_kick"):
  42. $AnimatedSprite3D.play("reverse_kick");
  43. isAttacking = true;
  44.  
  45. if Input.is_action_just_pressed("punch"):
  46. $AnimatedSprite3D.play("punch");
  47. isAttacking = true;
  48.  
  49. if is_on_floor() && Input.is_action_just_pressed("jump"):
  50. movement.y = jump_impulse;
  51. elif !is_on_floor():
  52. $AnimatedSprite3D.play("jumping");
  53. isAttacking = false;
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61. movement = move_and_slide(movement, Vector3.UP * delta);
  62.  
  63. return movement.normalized();
  64.  
  65.  
  66.  
  67. func apply_gravity(delta):
  68. movement.y = movement.y + gravity;
  69.  
  70.  
  71. #func jump():
  72. #if is_on_floor() && Input.is_action_pressed("jump"):
  73. #isJumping = true;
  74. #movement.y = jump_impulse;
  75.  
  76.  
  77.  
  78.  
  79. func _on_AnimatedSprite3D_animation_finished():
  80. get_node("AnimatedSprite3D").play("reverse_kick")
  81. isAttacking = false;
  82.  
  83. get_node("AnimatedSprite3D").play("punch")
  84. isAttacking = false;
  85.  
  86. get_node("AnimatedSprite3D").play("jumping")
  87. isAttacking = false;
  88. isJumping = false;
  89.  
  90.  
  91.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement