About This E-Book EPUB is an open, industry-standard format for e-books. However, support for EPUB and its many features varies across reading devices and applications. Use your device or app settings to customize the presentation to your liking. Settings that you can customize often include font, font size, single or double column, landscape or portrait mode, and figures that you can click or tap to enlarge. For additional information about the settings and features on your reading device or app, visit the device manufacturer’s Web site. Many titles include programming code or configuration examples. To optimize the presentation of these elements, view the e-book in single-column, landscape mode and adjust the font size to the smallest setting. In addition to presenting code and configurations in the reflowable text format, we have included images of the code that mimic the presentation found in the print book; therefore, where the reflowable format may compromise the presentation of the code listing, you will see a “Click here to view code image” link. Click the link to view the print-fidelity code image. To return to the previous page viewed, click the Back button on your device or app. ® Unreal Engine VR Cookbook Developing Virtual Reality with UE4 Mitch McCaffrey Boston • Columbus • Indianapolis • New York • San Francisco • Amsterdam • Cape Town Dubai • London • Madrid • Milan • Munich • Paris • Montreal • Toronto • Delhi • Mexico City São Paulo • Sydney • Hong Kong • Seoul • Singapore • Taipei • Tokyo Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and the publisher was aware of a trademark claim, the designations have been printed with initial capital letters or in all capitals. The author and publisher have taken care in the preparation of this book, but make no expressed or implied warranty of any kind and assume no responsibility for errors or omissions. No liability is assumed for incidental or consequential damages in connection with or arising out of the use of the information or programs contained herein. For information about buying this title in bulk quantities, or for special sales opportunities (which may include electronic versions; custom cover designs; and content particular to your business, training goals, marketing focus, or branding interests), please contact our corporate sales department at corp- [email protected] or (800) 382-3419. For government sales inquiries, please contact [email protected]. For questions about sales outside the U.S., please contact [email protected]. Visit us on the Web: informit.com/aw Library of Congress Control Number: 2016958916 Copyright © 2017 Pearson Education, Inc. All rights reserved. Printed in the United States of America. This publication is protected by copyright, and permission must be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permissions, request forms and the appropriate contacts within the Pearson Education Global Rights & Permissions Department, please visit www.pearsoned.com/permissions/. The following are registered trademarks of Google: Android™, Daydream™, Google Cardboard™. Steam VR is a registered trademark of Valve Corporation. Oculus Rift is a registered trademark of Oculus VR, LLC. Samsung Gear VR is a registered trademark of Samsung Electronics Co., Ltd. PlayStation VR is a registered trademark of Sony Interactive Entertainment Inc. Unreal Engine is a registered trademark of Epic Games, Inc., in the United States of America and elsewhere. ISBN-13: 978-0-13-464917-7 ISBN-10: 0-13-464917-6 1 17 Editor-in-Chief Mark L. Taub Executive Editor Laura Lewin Development Editor Sheri Replin Managing Editor Sandra Schroeder Full-Service Production Manager Julie B. Nahil Project Editor Anna Popick Copy Editor Barbara Wood Indexer Dick Evans Proofreader Anna Popick Technical Reviewers Luis Cataldi Jeff Wilson Clinton Crumpler Editorial Assistant Olivia Basegio Cover Designer Chuti Prasertsith Compositor The CIP Group ® Praise for Unreal Engine VR Cookbook “I’ve been a fan of Mitch’s work for quite some time. Back in early 2014, Mitch was exploring new locomotion mechanics in Unreal Engine for VR characters and sharing his findings, as well as numerous sample files, on the www.unrealengine.com forums in massive ongoing threads. Even in the early days of VR exploration, his work was helpful to many newcomers working to understand the issues of designing for a comfortable virtual experience. With his YouTube channel, Mitch’s VR Labs, he helped thousands of people understand the foundations of locomotion and interaction mechanics with clear and concise UE4 videos. I’m thrilled that he has taken the time to bring all his knowledge and experience in working with Unreal Engine and virtual reality to the Unreal® Engine VR Cookbook. With the current attention and appetite for understanding how best to work in the exciting medium of virtual reality with Unreal Engine, I think Mitch is uniquely qualified to share this book with the world.” —Luis Cataldi, Unreal Engine Education, Epic Games, Inc. Contents Preface Acknowledgments About the Author Part I: Getting Started 1 Terminology and Best Practices Terminology Devices Software Unreal Engine Best Practices Summary 2 Head Mounted Display Setup Gear VR Gear VR Project Setup Gear VR Global Menu Setup Gear VR Global Menu Progress Material Rift and Vive Rift and Vive Project Setup Rift and Vive Tracking Origins Summary 3 Toolkit Generic Function Library Oculus Function Library Steam VR Function Library Summary Part II: Recipes 4 Trace Interaction Understanding Trace Interaction Understanding Interfaces Setting Up Trace Interaction Basic Project Setup Interaction Interface Setup Interaction Component Interaction Pawn Setup Setting Up a Basic Interactive Object Summary Exercises 5 Teleportation Setting Up Teleportation Parabolic Tracing Visualizing the Teleport Visualization Material Visualization Actor Simple Teleportation Volume Summary Exercises 6 Unreal Motion Graphics and 2D User Interfaces Challenges with 2D UI in VR History and Compatibility of UMG Basic VR Menu Menu Actor Menu Pawn Custom Menu Interaction Implementing Custom Menu Interaction: Approach 1 Implementing Custom Menu Interaction: Approach 2 Summary Exercises 7 Character Inverse Kinematics Introduction to Inverse Kinematics Setting Up Head IK Mirror Creation IK Pawn Head IK Animation Blueprint Setting Up Hand IK Adding Motion Controllers to Your Pawn Hand IK Animation Blueprint Summary Exercises 8 Motion Controller Interaction