antifall_rb.gd 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. extends RigidBody
  2. var start_pos=Vector3()
  3. var stop_time=0.0
  4. var iTime=0.0
  5. func _ready():
  6. start_pos=self.translation
  7. func _process(delta):
  8. iTime+=delta
  9. anti_fall()
  10. sphere_pos()
  11. func anti_fall():
  12. if(self.translation.length()>100)&&(self.mode==RigidBody.MODE_RIGID):
  13. self.mode=RigidBody.MODE_KINEMATIC
  14. self.set_visible(false)
  15. stop_time=iTime
  16. if(iTime-stop_time>1.0)&&(self.mode==RigidBody.MODE_KINEMATIC):
  17. self.translation=start_pos+Vector3(0,2,0)
  18. self.mode=RigidBody.MODE_RIGID
  19. self.set_visible(true)
  20. func sphere_pos():
  21. get_node("../../p1/p1/spheres/"+self.name).translation=self.translation
  22. get_node("../../p1/p1/spheres/"+self.name).rotation=self.rotation
  23. get_node("../../p2/p2/spheres/"+self.name).translation=self.translation
  24. get_node("../../p2/p2/spheres/"+self.name).rotation=self.rotation
  25. get_node("../../p3/p3/spheres/"+self.name).translation=self.translation
  26. get_node("../../p3/p3/spheres/"+self.name).rotation=self.rotation
  27. get_node("../../p4/p4/spheres/"+self.name).translation=self.translation
  28. get_node("../../p4/p4/spheres/"+self.name).rotation=self.rotation
  29. get_node("../../p5/p5/spheres/"+self.name).translation=self.translation
  30. get_node("../../p5/p5/spheres/"+self.name).rotation=self.rotation