Player_bak.gd 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. extends KinematicBody
  2. # physics
  3. var moveSpeed : float = 5.0
  4. # cam look
  5. var minLookAngle : float = -90.0
  6. var maxLookAngle : float = 90.0
  7. var lookSensitivity : float = 10.0
  8. var ray: RayCast
  9. # vectors
  10. var vel : Vector3 = Vector3()
  11. var mouseDelta : Vector2 = Vector2()
  12. onready var camera : Camera = get_node("Camera")
  13. func _ready():
  14. move_and_slide(Common.latLonToGlobal(0,0,1750), Vector3.UP)
  15. func _process(delta):
  16. # rotate the camera along the x axis
  17. camera.rotation_degrees.x -= mouseDelta.y * lookSensitivity * delta
  18. # clamp camera x rotation axis
  19. camera.rotation_degrees.x = clamp(camera.rotation_degrees.x, minLookAngle, maxLookAngle)
  20. # rotate the player along their y-axis
  21. rotation_degrees.y -= mouseDelta.x * lookSensitivity * delta
  22. # reset the mouseDelta vector
  23. mouseDelta = Vector2()
  24. var origin = get_global_transform().origin
  25. .get_parent().get_node("UI/2").text="latlonhight: "+str(Common.globalToLatLon(origin.x,origin.y,origin.z, origin.length()))+","+str(origin.length())
  26. func _input(event):
  27. if event is InputEventMouseMotion and Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED:
  28. mouseDelta = event.relative
  29. func _physics_process(delta):
  30. # reset the x and z velocity
  31. vel.x = 0
  32. vel.y = 0
  33. vel.z = 0
  34. var input = Vector3()
  35. # movement inputs
  36. if Input.is_action_pressed("move_forward"):
  37. input.y -= 1
  38. if Input.is_action_pressed("move_backward"):
  39. input.y += 1
  40. if Input.is_action_pressed("move_left"):
  41. input.x -= 1
  42. if Input.is_action_pressed("move_right"):
  43. input.x += 1
  44. if Input.is_action_pressed("move_up"):
  45. input.z += 1
  46. if Input.is_action_pressed("move_down"):
  47. input.z -= 1
  48. input = input.normalized()
  49. # get the forward and right directions
  50. var forward = global_transform.basis.z
  51. var right = global_transform.basis.x
  52. var up = global_transform.basis.y
  53. var relativeDir = (forward * input.y + right * input.x + up * input.z)
  54. var moveSpeed2 = moveSpeed
  55. if Input.is_action_pressed("sprint"):
  56. moveSpeed2 = moveSpeed * 3
  57. # set the velocity
  58. vel.x = relativeDir.x * moveSpeed2
  59. vel.z = relativeDir.z * moveSpeed2
  60. vel.y = relativeDir.y * moveSpeed2
  61. var gravity = self.global_transform.origin.normalized()
  62. # move the player
  63. vel = move_and_slide(vel, Vector3.UP)
  64. #ray = ray.look_at(self.global_transform.origin, Vector3.UP)
  65. var pos = self.global_transform.origin
  66. var polPos = Common.globalToLatLon(pos.x,pos.y,pos.z)
  67. var rotationDeg=get_rotation_degrees().x
  68. var posNorm=abs(pos.normalized().y)
  69. var targetRot = posNorm * 90
  70. #if rotationDeg < targetRot:
  71. #rotate_x(1)
  72. #elif rotationDeg > targetRot:
  73. #rotate_x(-1)
  74. .get_parent().get_node("UI/1").text="x:%s y:%s z:%s" %[pos.x, pos.y, pos.z]
  75. #.get_node("UI/3").text="LatLonPos=="+str(latLonToGlobal( self.global_transform.origin.x,self.global_transform.origin.y))