Skip to content

Commit

Permalink
made FirstPersonController remember original position and rotation on…
Browse files Browse the repository at this point in the history
… disable/enable.
  • Loading branch information
petteramland committed Oct 31, 2023
1 parent b6c1621 commit 346b974
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions ursina/prefabs/first_person_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,16 @@ def land(self):
def on_enable(self):
mouse.locked = True
self.cursor.enabled = True
if hasattr(self, 'camera_pivot'):
camera.world_parent = self.camera_pivot
# restore parent and position/rotation from before disablem in case you moved the camera in the meantime.
if hasattr(self, 'camera_pivot') and hasattr(self, '_original_camera_transform'):
camera.parent = self.camera_pivot
camera.transform = self._original_camera_transform


def on_disable(self):
mouse.locked = False
self.cursor.enabled = False
self._original_camera_transform = camera.transform # store original position and rotation
camera.world_parent = scene


Expand Down

0 comments on commit 346b974

Please sign in to comment.