├── .gitignore ├── CameraControl.gd ├── LICENSE ├── README.md └── Screenshot.gd /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Godot-specific ignores 3 | .import/ 4 | export.cfg 5 | export_presets.cfg 6 | 7 | # Mono-specific ignores 8 | .mono/ 9 | data_*/ 10 | -------------------------------------------------------------------------------- /CameraControl.gd: -------------------------------------------------------------------------------- 1 | extends Camera 2 | 3 | # DESCRIPTION 4 | # Move your camera smoothly between camera positions. Meant for 3D. 5 | # 6 | # HOWTO 7 | # 1. Attach the script to your camera. The camera should preferably be a 8 | # child of the root-node of the scene. 9 | # 2. Create one or more nodes of the type Position3D. 10 | # 3. Add each of the Position3D-nodes to a group called "camera_positions". 11 | # 4. Move each node to its desired location. The easiest way is to start 12 | # the game, then adjust location and rotation in the editor - your game 13 | # will update on the fly. 14 | # 5. Start the game (if you haven't already) and press C to switch camera. 15 | # 16 | # Tested in Godot 3.2, Linux 17 | # By Filip Lundby, https://twitter.com/skooterkurt 18 | 19 | # Adjust the movement speed between camera locations 20 | export var TRANSFORM_SPEED : float = 3 21 | 22 | var _camera_transforms : Array = [] 23 | var _current_camera : int = 0 24 | var _current_transform 25 | var _target_transform 26 | 27 | func _ready(): 28 | _camera_transforms = get_tree().get_nodes_in_group("camera_positions") 29 | _current_transform = _camera_transforms[_current_camera].global_transform 30 | _target_transform = _current_transform 31 | 32 | func _input(event): 33 | # Cycle between camera positions 34 | if event is InputEventKey and event.pressed: 35 | if event.scancode == KEY_C: 36 | if _current_camera + 1 < len(_camera_transforms): 37 | _current_camera += 1 38 | else: 39 | _current_camera = 0 40 | 41 | func _physics_process(delta): 42 | # Set camera to new position/rotation 43 | _target_transform = _camera_transforms[_current_camera].global_transform 44 | _current_transform = _current_transform.interpolate_with(_target_transform, delta * TRANSFORM_SPEED) 45 | global_transform = _current_transform 46 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Filip Lundby 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # Godot Snippets 3 | 4 | ## About 5 | 6 | If you find any of these scripts useful, consider throwing some credit my way on Twitter, [@skooterkurt](https://twitter.com/skooterkurt), or just DM me. I'd love to see your cool project :) 7 | 8 | ## Bugs 9 | 10 | Found an issue? [Please let me know](https://twitter.com/messages/compose?recipient_id=259365053). 11 | 12 | 13 | ## MIT License 14 | 15 | Copyright (c) 2020 Filip Lundby 16 | 17 | Permission is hereby granted, free of charge, to any person obtaining a copy 18 | of this software and associated documentation files (the "Software"), to deal 19 | in the Software without restriction, including without limitation the rights 20 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 21 | copies of the Software, and to permit persons to whom the Software is 22 | furnished to do so, subject to the following conditions: 23 | 24 | The above copyright notice and this permission notice shall be included in all 25 | copies or substantial portions of the Software. 26 | 27 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 28 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 29 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 30 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 31 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 32 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 33 | SOFTWARE. 34 | -------------------------------------------------------------------------------- /Screenshot.gd: -------------------------------------------------------------------------------- 1 | extends Node 2 | 3 | # Screenshots without hiccups using threads. 4 | # Attach the script to a Node, start your game and hit F11 5 | # 6 | # Tested in Godot 3.2 beta 5, Linux 7 | # By Filip Lundby, https://twitter.com/skooterkurt 8 | 9 | var _root_directory = "user://" 10 | var _screenshot_directory = "screenshots" 11 | var _capture_tasks = [] 12 | var _random = RandomNumberGenerator.new() 13 | 14 | func _ready(): 15 | # Create directory 16 | var screenshot_directory = "%s/%s" % [_root_directory, _screenshot_directory] 17 | Directory.new().make_dir(screenshot_directory) 18 | 19 | func _input(event): 20 | if event is InputEventKey and event.pressed: 21 | if event.scancode == KEY_F11: 22 | _capture() 23 | 24 | func _capture(): 25 | # Start thread for capturing images 26 | var task = Thread.new() 27 | task.start(self, "_capture_thread", null) 28 | _capture_tasks.append(task) 29 | 30 | func _capture_thread(_arg): 31 | # Save image 32 | _random.randomize() 33 | var image_filename = "capture_%s%s.png" % [OS.get_unix_time(), _random.randi_range(100000, 999999)] 34 | var godot_path = "%s/%s/%s" % [_root_directory, _screenshot_directory, image_filename] 35 | var image = get_viewport().get_texture().get_data() 36 | image.flip_y() 37 | image.save_png(godot_path) 38 | 39 | # Print path to image (just for debugging - remove if you like) 40 | var os_separator = "\\" if OS.get_name() == "Windows" else "/" 41 | var os_path = PoolStringArray([OS.get_user_data_dir(), _screenshot_directory, image_filename]).join(os_separator) 42 | print ("Screenshot saved to: %s" % os_path) 43 | 44 | func _exit_tree(): 45 | for task in _capture_tasks: 46 | task.wait_to_finish() 47 | --------------------------------------------------------------------------------