summaryrefslogtreecommitdiffstats
path: root/Ship.gd
blob: db200bd735943934d0ef8f58cf115b357fc12731 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
extends BuoyantBody

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():
    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"):
        if ship_cam.current:
            player_cam.current = true
        else:
            ship_cam.current = true
    lock_camera_to_boat()

func _input(event):
    if event is InputEventMouseMotion:
        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")
    if stick != 0.0:
        self.add_torque(Vector3.UP*stick*ang_acceleration*self.mass)