Moving from Unity to Godot an In-Depth Handbook to Godot for Unity Users
Total Page:16
File Type:pdf, Size:1020Kb
Moving from Unity to Godot An In-Depth Handbook to Godot for Unity Users Alan Thorn Moving from Unity to Godot: An In-Depth Handbook to Godot for Unity Users Alan Thorn High Wycombe, UK ISBN-13 (pbk): 978-1-4842-5907-8 ISBN-13 (electronic): 978-1-4842-5908-5 https://doi.org/10.1007/978-1-4842-5908-5 Copyright © 2020 by Alan Thorn This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission or information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed. Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights. While the advice and information in this book are believed to be true and accurate at the date of publication, neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or omissions that may be made. The publisher makes no warranty, express or implied, with respect to the material contained herein. Managing Director, Apress Media LLC: Welmoed Spahr Acquisitions Editor: Spandana Chatterjee Development Editor: James Markham Coordinating Editor: Divya Modi Cover designed by eStudioCalamar Cover image designed by Pixabay Distributed to the book trade worldwide by Springer Science+Business Media New York, 233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail [email protected], or visit www.springeronline.com. Apress Media, LLC is a California LLC and the sole member (owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc is a Delaware corporation. For information on translations, please e-mail [email protected], or visit http://www. apress.com/rights-permissions. Apress titles may be purchased in bulk for academic, corporate, or promotional use. eBook versions and licenses are also available for most titles. For more information, reference our Print and eBook Bulk Sales web page at http://www.apress.com/bulk-sales. Any source code or other supplementary material referenced by the author in this book is available to readers on GitHub via the book’s product page, located at www.apress.com/ 978-1-4842-5907-8. For more detailed information, please visit http://www.apress.com/ source-code. Printed on acid-free paper Table of Contents About the Author ................................................................................vii About the Technical Reviewer .............................................................ix Introduction .........................................................................................xi Chapter 1: Introducing Godot: Why Migrate? .......................................1 Getting and Installing Godot ..................................................................................2 Why Use Godot? ....................................................................................................3 Godot Is Free ...................................................................................................3 Godot Is Open Source ......................................................................................4 Godot Is Evolving .............................................................................................5 Godot Is Supported ..........................................................................................5 Godot Is About Games and Experiences ..........................................................6 Godot and C# .........................................................................................................6 Getting Started with C# in Godot ...........................................................................9 Summary.............................................................................................................14 Chapter 2: Godot Fundamentals .........................................................15 Godot Projects .....................................................................................................16 Editor Interface ...................................................................................................20 Creating and Editing Scenes ...............................................................................21 Scenes and Nodes – Adding a Cube ...................................................................26 iii TABLE OF CONTENTS Navigation and Transformation ...........................................................................33 Zoom ..............................................................................................................35 Pan ................................................................................................................36 Frame and Orbit .............................................................................................36 First-Person Controls .....................................................................................37 Selecting, Moving, Rotating, and Scaling Nodes............................................38 Local and World Space Transforms .....................................................................40 Scene vs. Game Mode ........................................................................................41 Resources ...........................................................................................................50 Summary.............................................................................................................52 Chapter 3: Scripting with C# in Godot: Common Tasks ......................53 . NET and Build Problems with C# .......................................................................55 Building a Hello World Program ..........................................................................61 Working with Nodes ............................................................................................67 Iterating Through Child Nodes.............................................................................68 Finding Nodes by Name ......................................................................................70 Finding Nodes by Path ........................................................................................71 Godot Groups vs. Unity Tags ................................................................................73 Accessing Variables in the Inspector ..................................................................78 Variables As Properties – GetComponent? ..........................................................80 NodePaths and Node References........................................................................81 Set an Object’s Position ......................................................................................83 Make an Object Move Smoothly .........................................................................85 Make an Object Rotate Smoothly ........................................................................86 Detecting When an Object Enters a Trigger .........................................................87 Viewing Spatial Nodes ........................................................................................96 iv TABLE OF CONTENTS Reading Player Input ...........................................................................................98 Summary...........................................................................................................103 Chapter 4: Making a 2D Game ..........................................................105 Configuring a 2D Project ...................................................................................106 Importing Assets ...............................................................................................110 Creating the Player Character ...........................................................................112 Building a Level – Tilemaps and Tilesets ..........................................................128 World Collisions ................................................................................................139 2 D Lighting ........................................................................................................148 Pickups .............................................................................................................152 Timers and Countdowns ...................................................................................156 Summary...........................................................................................................160 Chapter 5: 3D Lighting and Materials ...............................................161 Lighting Fundamentals .....................................................................................162 Exploring Light Types ........................................................................................165