summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordusoleil <howcansocksbereal@gmail.com>2022-09-15 20:52:36 -0400
committerdusoleil <howcansocksbereal@gmail.com>2022-09-15 20:52:36 -0400
commitdaf97e7b02a0e0f1bd9cab91b990d45773aab160 (patch)
tree3738d7f043ff35149ac1116affa736b13f7d7968
parent3e09d6846e3200881c0dbc60f9dd805ec2050c30 (diff)
downloadgame_jam49-daf97e7b02a0e0f1bd9cab91b990d45773aab160.tar.gz
game_jam49-daf97e7b02a0e0f1bd9cab91b990d45773aab160.zip
Add a ship camera (swap with Q) for testing world movement and generation
-rw-r--r--Main.tscn6
-rw-r--r--Ship.gd27
-rw-r--r--project.godot5
3 files changed, 38 insertions, 0 deletions
diff --git a/Main.tscn b/Main.tscn
index 495c034..6612a43 100644
--- a/Main.tscn
+++ b/Main.tscn
@@ -150,6 +150,12 @@ 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="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 )
+far = 5000.0
+
[node name="crates" type="Spatial" parent="."]
[node name="crate" parent="crates" instance=ExtResource( 5 )]
diff --git a/Ship.gd b/Ship.gd
index b89e3b9..231057c 100644
--- a/Ship.gd
+++ b/Ship.gd
@@ -2,6 +2,33 @@ extends RigidBody
export var ang_acceleration = 240.0
+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
+
+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
+ else:
+ 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)
+
func _integrate_forces(_state):
var stick = Input.get_axis("ship_right","ship_left")
if stick != 0.0:
diff --git a/project.godot b/project.godot
index af0d510..0b05f85 100644
--- a/project.godot
+++ b/project.godot
@@ -96,6 +96,11 @@ ship_right={
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777233,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
]
}
+camera_swap={
+"deadzone": 0.5,
+"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":81,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
+ ]
+}
[layer_names]