Player.gd 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. extends Spatial
  2. onready var MAIN = find_parent("MAIN")
  3. var speed = 0.4
  4. var normal = Vector3(0.0,1.0,0.0)
  5. var rotspeed = 0.01*1024.0
  6. var theta_limit = PI/2.0*0.9
  7. var camtheta = 0
  8. var body_phi = 0
  9. var cam_speed = Vector2(0,0)
  10. var camera
  11. var can_look_around = true
  12. var current_hand = ""
  13. var beta_speed = 0.01
  14. onready var camera_default_transform = $Camera.transform
  15. onready var vp_size = get_viewport().size
  16. class_name Player
  17. # Called when the node enters the scene tree for the first time.
  18. func _input(event):
  19. if event is InputEventMouseMotion:
  20. if not event.relative.length()>100.0:
  21. body_phi= wrapf(body_phi-event.relative.x * rotspeed/vp_size.x,-PI,PI)
  22. camtheta = clamp(camtheta - event.relative.y*rotspeed/vp_size.x,-theta_limit,theta_limit)
  23. func _process(_delta):
  24. if Input.is_action_pressed("ui_down"):
  25. tune_beta(false, _delta)
  26. if Input.is_action_pressed("ui_up"):
  27. tune_beta(true, _delta)
  28. if can_look_around:
  29. camera.rotation.x += (camtheta-camera.rotation.x)*0.3
  30. var dphi = body_phi - rotation.y
  31. if dphi>PI:
  32. dphi = dphi - 2*PI
  33. elif dphi<-PI:
  34. dphi = dphi + 2*PI
  35. dphi*=0.3
  36. rotation.y=wrapf(rotation.y+dphi,-PI,PI)
  37. func tune_beta(up, delta):
  38. var dir = Vector3(0,0,1)
  39. var step = (1 if up else -1)*delta
  40. MAIN.beta.z = wrapf(MAIN.beta.z+step, 0, 1)
  41. func _ready():
  42. camera = $Camera