diff options
Diffstat (limited to 'godot/scripts/cameras')
| -rw-r--r-- | godot/scripts/cameras/PlayerCamGDS.gd | 79 | ||||
| -rw-r--r-- | godot/scripts/cameras/plane_armcam.gd | 6 | ||||
| -rw-r--r-- | godot/scripts/cameras/player_firstperson.gd | 33 |
3 files changed, 79 insertions, 39 deletions
diff --git a/godot/scripts/cameras/PlayerCamGDS.gd b/godot/scripts/cameras/PlayerCamGDS.gd new file mode 100644 index 0000000..ec46cf8 --- /dev/null +++ b/godot/scripts/cameras/PlayerCamGDS.gd @@ -0,0 +1,79 @@ +extends ClippedCamera + +var _modes = ["STATIC", "FIRSTPERSON", "THIRDPERSON", "ARM", "FREECAM"] +var mode = "STATIC" #STATIC, FIRSTPERSON, THIRDPERSON, ARM, FREECAM + +#first/third person variables +var head : Spatial = null +var neck : Spatial = null +var player : RigidBody = null + +#third person/arm variables +var arm : SpringArm = null + +var mouse_axis := Vector2() +var mouse_sensitivity = 12.0 + +func _ready(): + Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED) + current = true + +func _input(event): + if event is InputEventMouseMotion and Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED: + mouse_axis = event.relative + match mode: + "FIRSTPERSON": + mouse_firstperson() + "THIRDPERSON": + mouse_thirdperson() + "STATIC": + pass + "ARM": + mouse_arm() + "FREECAM": + mouse_freecam() + _: + pass + +func attach(new_parent: Node, c_mode, extra_path = "."): + if get_parent(): + get_parent().remove_child(self) + if c_mode in _modes: + mode = c_mode + if mode == "FIRSTPERSON": + head = new_parent.head; neck = new_parent.neck; + arm = null; + elif mode == "THIRDPERSON": + head = new_parent.head; neck = new_parent.neck; + arm = new_parent.arm + elif mode == "ARM": + head = null; neck = null; + arm = new_parent.arm + else: + head = null; neck = null; arm = null; + new_parent.get_node(extra_path).add_child(self) + transform = Transform.IDENTITY + +func mouse_firstperson() -> void: + if mouse_axis.length_squared() > 0: + var horizontal: float = -mouse_axis.x * (mouse_sensitivity / 100) + var vertical: float = -mouse_axis.y * (mouse_sensitivity / 100) + + neck.rotate_y(deg2rad(horizontal)) + head.rotate_x(deg2rad(vertical)) + + #vertical clamp + head.rotation_degrees.x = clamp(head.rotation_degrees.x, -90, 90) + +func mouse_thirdperson() -> void: + arm.rotation_degrees.x = clamp(rotation_degrees.x-mouse_axis.y*(mouse_sensitivity / 100),-90,90) + arm.rotation_degrees.y -= mouse_axis.x*(mouse_sensitivity / 100) + head.rotation_degrees.x = arm.rotation_degrees.x + neck.rotation_degrees.y = arm.rotation_degrees.y + +func mouse_arm() -> void: + arm.rotation_degrees.x = clamp(rotation_degrees.x-mouse_axis.y*(mouse_sensitivity / 100),-70,70) + arm.rotation_degrees.y -= mouse_axis.x*(mouse_sensitivity / 100) + +func mouse_freecam() -> void: + pass diff --git a/godot/scripts/cameras/plane_armcam.gd b/godot/scripts/cameras/plane_armcam.gd index edb0284..68b4852 100644 --- a/godot/scripts/cameras/plane_armcam.gd +++ b/godot/scripts/cameras/plane_armcam.gd @@ -14,12 +14,6 @@ func _ready(): func _input(event): if $ClippedCamera.current: - if Input.is_action_just_pressed("menu"): #toggle mouse capture on esc - if Input.get_mouse_mode() == Input.MOUSE_MODE_VISIBLE: - Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED) - else: - Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE) - if Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED: if event is InputEventMouseMotion: rotation_degrees.x = clamp(rotation_degrees.x-event.relative.y*0.1,-70,70) diff --git a/godot/scripts/cameras/player_firstperson.gd b/godot/scripts/cameras/player_firstperson.gd deleted file mode 100644 index ace49e6..0000000 --- a/godot/scripts/cameras/player_firstperson.gd +++ /dev/null @@ -1,33 +0,0 @@ -extends Camera - - -var mouse_axis := Vector2() -var mouse_sensitivity = 12.0 - -func _ready(): - Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE) - current = false - - -func _input(event): - if current: - if Input.is_action_just_pressed("menu"): #toggle mouse capture on esc - if Input.get_mouse_mode() == Input.MOUSE_MODE_VISIBLE: - Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED) - else: - Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE) - if event is InputEventMouseMotion and Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED: - mouse_axis = event.relative - if mouse_axis.length() > 0: - var horizontal: float = -mouse_axis.x * (mouse_sensitivity / 100) - var vertical: float = -mouse_axis.y * (mouse_sensitivity / 100) - - mouse_axis = Vector2() - - get_parent().rotate_y(deg2rad(horizontal)) - rotate_x(deg2rad(vertical)) - - var temp_rot: Vector3 = rotation_degrees - temp_rot.x = clamp(temp_rot.x, -90, 90) - get_parent().animationcontroller.rpc("lean",-1*temp_rot.x/90) - rotation_degrees = temp_rot |
