diff options
author | dusoleil <howcansocksbereal@gmail.com> | 2022-09-16 07:56:20 -0400 |
---|---|---|
committer | dusoleil <howcansocksbereal@gmail.com> | 2022-09-16 07:56:20 -0400 |
commit | f8d1f2dc1bd6356c33d023629fbef27f362c7aa2 (patch) | |
tree | 13b8b0e1a0d29562f66ddb20b1490bb471b4b0f8 | |
parent | 65baf0c396004d2ea36a871824898abc88f5977a (diff) | |
download | game_jam49-f8d1f2dc1bd6356c33d023629fbef27f362c7aa2.tar.gz game_jam49-f8d1f2dc1bd6356c33d023629fbef27f362c7aa2.zip |
Fix both cameras to follow the boat, but ignore its yaw
-rw-r--r-- | Main.tscn | 8 | ||||
-rw-r--r-- | Ship.gd | 31 | ||||
-rw-r--r-- | ship/ship/ViewPorts.gd | 3 |
3 files changed, 19 insertions, 23 deletions
@@ -48,9 +48,6 @@ light_color = Color( 0.85098, 0.47451, 0.0352941, 1 ) shadow_enabled = true directional_shadow_blend_splits = true -[node name="fps_controller" parent="." instance=ExtResource( 1 )] -transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 17, 44 ) - [node name="Ground" type="StaticBody" parent="."] transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -10, 0 ) collision_layer = 4 @@ -150,10 +147,13 @@ transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 9.77011, -3.30323, -29.0883 ) [node name="Float14" parent="ShipRigidBody" instance=ExtResource( 4 )] transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 9.77011, -3.30323, -49.022 ) +[node name="fps_controller" parent="ShipRigidBody" instance=ExtResource( 1 )] +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 17, 44 ) + [node name="CameraPivot" type="Spatial" parent="ShipRigidBody"] [node name="Camera" type="Camera" parent="ShipRigidBody/CameraPivot"] -transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.30045, 0 ) +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 50, 70 ) far = 5000.0 [node name="crates" type="Spatial" parent="."] @@ -2,32 +2,29 @@ extends RigidBody export var ang_acceleration = 240.0 +onready var player_cam_pivot = $"fps_controller" +onready var player_cam = player_cam_pivot.get_node("Camera") +onready var ship_cam_pivot = $"CameraPivot" +onready var ship_cam = ship_cam_pivot.get_node("Camera") + func lock_camera_to_boat(): - var boat = self - var cam = $"CameraPivot" - cam.look_at_from_position(Basis(Vector3.UP*boat.global_transform.basis.get_euler().y) * (boat.global_transform.origin + Vector3.UP*50.0 + Vector3.BACK*70.0), boat.global_transform.origin, Vector3.UP) - var boat_direction = boat.global_transform.basis - boat_direction = Basis(Vector3.UP*boat_direction.get_euler().y) - cam.global_transform.basis = boat_direction - cam.global_transform.origin.y = 50.0 + player_cam_pivot.global_transform.basis = Basis(Vector3.UP*player_cam_pivot.global_transform.basis.get_euler().y) + ship_cam_pivot.global_transform.basis = Basis(Vector3.UP*ship_cam_pivot.global_transform.basis.get_euler().y) func _physics_process(_delta): if Input.is_action_just_pressed("camera_swap"): - var cam = $"CameraPivot/Camera" - if cam.current: - $"/root/Main/fps_controller/Camera".current = true + if ship_cam.current: + player_cam.current = true else: - cam.current = true + ship_cam.current = true lock_camera_to_boat() func _input(event): - var pivot = $"CameraPivot" - var cam = pivot.get_node("Camera") if event is InputEventMouseMotion: - cam.rotation.x += -event.relative.y * Settings.mouse_sens - cam.rotation.x = clamp(cam.rotation.x, -1.2, 1.2) - cam.rotation.y += -event.relative.x * Settings.mouse_sens - cam.rotation.y = wrapf(cam.rotation.y, 0, TAU) + ship_cam.rotation.x += -event.relative.y * Settings.mouse_sens + ship_cam.rotation.x = clamp(ship_cam.rotation.x, -1.2, 1.2) + ship_cam.rotation.y += -event.relative.x * Settings.mouse_sens + ship_cam.rotation.y = wrapf(ship_cam.rotation.y, 0, TAU) func _integrate_forces(_state): var stick = Input.get_axis("ship_right","ship_left") diff --git a/ship/ship/ViewPorts.gd b/ship/ship/ViewPorts.gd index 2e8e800..aac098c 100644 --- a/ship/ship/ViewPorts.gd +++ b/ship/ship/ViewPorts.gd @@ -11,5 +11,4 @@ func _physics_process(_delta): for i in self.get_child_count(): var viewport = self.get_child(i) var cam = viewport.get_node("Camera") - cam.global_transform = camera_locations[i] - cam.global_transform = self.global_transform * cam.global_transform + cam.global_transform = self.global_transform * camera_locations[i] |