Human.gd 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. extends Chattable
  2. class_name Human
  3. var extension_max = 30
  4. var anitime = 0.5
  5. var footprint_size = 0.6
  6. var warphook_in
  7. var warphook_out
  8. var workplace = null #nodename
  9. var transit_point = null #nodename
  10. # vvvv needed Pads node goes here when guest is called
  11. var queued_start = null #workaround for MAIN being busy and forcing deferred calls
  12. func transit(target_transform, transit_transform = null):
  13. if transit_transform:
  14. go_to_point(transit_transform,self,"go_to_point",target_transform)
  15. else:
  16. go_to_point(target_transform)
  17. func go_to_point(transf, cb_object = null, cb_method = null, cb_arg = null):
  18. var tw
  19. tw = SDTween.new(cb_object,cb_method,cb_arg) #SDtween knows what to do with null args, no need to dupe
  20. tw.interpolate_property(self,"global_transform",global_transform,transf,1,Tween.TRANS_CUBIC,Tween.EASE_IN_OUT)
  21. add_child(tw)
  22. tw.start()
  23. func _ready():
  24. if queued_start:
  25. visible = false
  26. global_transform=queued_start.gl_inpoint()
  27. warp_in()
  28. queued_start=null
  29. # preventing player from interacting with things while they are moving
  30. _set_noninteractable()
  31. var t =SDTimer.new(self,"_set_interactable")
  32. t.wait_time = 3
  33. add_child(t)
  34. t.start()
  35. pass
  36. func leave(exit = "Pads2"):
  37. _set_noninteractable()
  38. transit(MAIN.find_node(exit).gl_outpoint(), MAIN.find_node(transit_point).global_transform)
  39. func go_to_workplace():
  40. transit(MAIN.find_node(workplace).global_transform, MAIN.find_node(transit_point).global_transform )
  41. func _set_noninteractable():
  42. var colshape = $"Spatial/human"
  43. colshape.set_collision_layer_bit(0,false)
  44. colshape.set_collision_layer_bit(2,false)
  45. func _set_interactable():
  46. var colshape = $"Spatial/human"
  47. colshape.set_collision_layer_bit(0,true)
  48. colshape.set_collision_layer_bit(2,true)
  49. func warp(direction):
  50. var tw1 = SDTween.new(self,"warp_cleaning")
  51. var tw2 = SDTween.new()
  52. tw1.interpolate_property(self,"scale",Vector3(1,1,1), Vector3(1,1,extension_max), anitime,Tween.TRANS_CUBIC,Tween.EASE_IN_OUT)
  53. tw2.interpolate_property(self,"translation",translation, translation+direction * extension_max*footprint_size, anitime,Tween.TRANS_CUBIC,Tween.EASE_IN_OUT)
  54. for t in [tw1,tw2]:
  55. add_child(t)
  56. t.start()
  57. var cloak = find_node("human_robes")
  58. if cloak is Cloak:
  59. cloak.warp(anitime)
  60. if warphook_out:
  61. call(warphook_out)
  62. func warp_cleaning():
  63. #print("cleaning from warp")
  64. if self.get("player_piggyback"): # when player is piggybacking
  65. print("property was found on an npc and active")
  66. if MAIN.dna_scanned:
  67. get_tree().change_scene("res://END5.tscn")
  68. else:
  69. get_tree().change_scene("res://END3.tscn")
  70. else:
  71. #print("player camera was not found")
  72. queue_free()
  73. func warp_in():
  74. var direction
  75. var tw1 = SDTween.new(self,"go_to_workplace")
  76. var tw2 = SDTween.new()
  77. var initial_trans = translation
  78. translation = translation-transform.basis.z*extension_max*footprint_size
  79. tw1.interpolate_property(self,"scale",Vector3(1,1,extension_max), Vector3(1,1,1), anitime,Tween.TRANS_CUBIC,Tween.EASE_IN_OUT)
  80. tw2.interpolate_property(self,"translation",translation, initial_trans, anitime,Tween.TRANS_CUBIC,Tween.EASE_IN_OUT)
  81. for t in [tw1,tw2]:
  82. add_child(t)
  83. t.start()
  84. var cloak = find_node("human_robes")
  85. if cloak is Cloak:
  86. cloak.warp(anitime,true)
  87. if warphook_in:
  88. call(warphook_in)
  89. visible = true