summaryrefslogtreecommitdiffstats
path: root/Ship.gd
blob: 231057cfc3e5bad35a6d3bfe49dc47d378b98f57 (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
33
34
35
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:
        self.add_torque(Vector3.UP*stick*ang_acceleration)