Advertisement
ignacy123

MINECRFAT in Godot Engine - Kinematic Body

Aug 2nd, 2023 (edited)
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. extends KinematicBody
  2.  
  3. var sensitivity = 0.1
  4. var speed = 10
  5. var is_jump = false
  6. var jump_time = 0
  7. var is_fly = false
  8.  
  9. func _ready():
  10. Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
  11.  
  12. func _process(delta):
  13.  
  14. var jump_var = 100
  15. var move_vector = Vector3.ZERO
  16.  
  17. if(!is_on_floor()):
  18. if(!is_fly):
  19. move_and_slide(Vector3(0,-2,0)*10, Vector3(0,1,0))
  20.  
  21. if Input.is_action_just_pressed("jump"):
  22. if(is_on_floor()):
  23. jump_time = 5
  24. is_jump = true
  25. if is_jump:
  26. move_and_slide(Vector3(0,1,0)*50)
  27. jump_time -= 1
  28. if (jump_time <= 0):
  29. is_jump = false
  30. if Input.is_action_pressed("fly"):
  31. move_vector.y += 1
  32. is_fly = true
  33. if Input.is_action_just_released("fly"):
  34. is_fly = false
  35. if Input.is_action_pressed("forward"):
  36. move_vector.z -= 1
  37. if Input.is_action_pressed("back"):
  38. move_vector.z += 1
  39. if Input.is_action_pressed("left"):
  40. move_vector.x -= 1
  41. if Input.is_action_pressed("right"):
  42. move_vector.x += 1
  43. if move_vector.length() > 1:
  44. move_vector = move_vector.normalized()
  45. if move_vector != Vector3.ZERO:
  46. var move_direction = global_transform.basis.xform(move_vector)
  47. move_and_slide(move_direction * speed)
  48.  
  49.  
  50. func _input(event):
  51. if event is InputEventMouseMotion:
  52. rotation_degrees.y -= event.relative.x * sensitivity
  53. rotation_degrees.x -= event.relative.y * sensitivity
  54. rotation_degrees.x = clamp(rotation_degrees.x, -89, 89)
  55.  
  56. # https://godotengine.org/asset-library/asset/533
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement