UFCEKU-20-3Web Games Programming Unity 3D Physics Colliders and Object Collisions.

Slides:



Advertisements
Similar presentations
KCPS Staff are now able to submit their own work orders for technology assistance as needed.
Advertisements

Understanding an Apps Architecture ASFA Computer Science: Principles Fall 2013.
Chapter 4.2 Collision Detection and Resolution. 2 Collision Detection Complicated for two reasons 1. Geometry is typically very complex, potentially requiring.
UFCFSU-30-13D Technologies for the Web Creating and Updating a Graphical Heads-Up Display (HUD)
INNER WORKINGS OF UNITY 3D. WHAT WE ARE GOING TO COVER Intro to Unity Physics & Game Objects Cameras & Lighting Textures & Materials Quaternions and Rotation.
UFCFX5-15-3Mobile Device Development Particle Systems.
UFCFSU-30-13D Technologies for the Web Creating and Using GUI Components.
Done already for your convenience! Telerik School Academy Unity 2D Game Development.
Chapter 4.2 Collision Detection and Resolution. 2 Collision Detection Complicated for two reasons 1. Geometry is typically very complex, potentially requiring.
UFCEKU-20-3Web Games Programming Game Physics for Collisions and Reactions.
Code ‘n Play Interactive Games with Unity & JavaScript.
1 TouchDevelop Chapter 8-10 Presenter: Jing Xu. 2 Outline Interactions Game Board Tiles and Printing.
Unity Lecture Unity Build-in Physics Engine. Unity contains powerful 3D physics engine NVIDIA PhysX Physics. Create immersive and visceral scenes with.
Networking Networking is done via a single component that is persistent in each machine’s game. This multiplayer manager component handles all Unity RPC.
UFCEKU-20-3Web Games Programming Unity 3D Basic Concepts Using and Creating Prefabs.
Computer Animation Rick Parent Computer Animation Algorithms and Techniques Collisions & Contact.
Web Games Programming An Introduction to Unity 3D.
Web Games Programming Unity Scripting Fundamentals.
UFCFS D Technologies for the Web Unity 3D: Review of Topics and Related Concepts.
Visual Basic.NET BASICS Lesson 1 A First Look at Microsoft Visual Basic.NET.
Game Maker Terminology
SE 320 – Introduction to Game Development Lecture 3: Unity’s Interface and Concepts Lecturer: Gazihan Alankuş Please look at the last two slides for assignments.
UFCFS D Technologies for the Web Unity Interface Features.
MCSE Guide to Microsoft Exchange Server 2003 Administration Chapter Five Managing Addresses.
Game Maker – Getting Started What is Game Maker?.
Yingcai Xiao Game Development with Unity3D. Outline IDE Engine Assets Tutorial Examples Inside.
Games Development Game Architecture: Entities CO2301 Games Development 1 Week 22.
UFCEK-20-3Web Games Programming Unity 3D: Review of Topics Publishing for the Web.
Chipmunk Physics Remember that we talked about this a bit when we did collision handlers for the space ship integration task (SpritesActionsPhysicsSound).
Unity GUI Creating and Using GUI Components. Agenda GUI Components GUI Layout Using Styles and Skins for Design ‘Look and Feel’ Scripting GUI Communication.
Unity3D Physics April 3, 2015 Comp Game Design Michael Shah.
Computer Game Design and Development
Advanced Games Development Game Physics CO2301 Games Development 1 Week 19.
Understand Databound Controls Windows Development Fundamentals LESSON 4.2A.
Tank Game Part 3 of 6. Secondary Weapons and Pick ups Pick ups will appear randomly in the battle area and can be collected by driving into them. Each.
UFCEKU-20-3Web Games Programming Instantiating World Objects.
UFCFSU-30-13D Technologies for the Web An Introduction to Unity 3D.
Computer Graphics Imaging Ying Zhu Georgia State University Lecture 29 Soft Bodies and Rigid Bodies.
Yingcai Xiao Game Development with Unity3D Inside/Outside Unity3D.
Game Maker Tutorials Introduction Clickball IntroductionClickball Where is it? Shooting Where is it?Shooting.
UFCEKU-20-3Web Games Programming Creating and Updating a Graphical Heads-Up Display (HUD)
Game Development with Unity3D
Unity 3D Rolfe Bozier 24-Apr-2017
Game development.
JavaScript, Sixth Edition
Quick Intro to Unity Lecture 2.
Game Development with Unity3D Inside/Outside Unity3D
Done already for your convenience!
3GB3 Game Design Unity 3D Basics.
Game development.
Unity 2D: Step by Step, Part 4
EEC-693/793 Applied Computer Vision with Depth Cameras
Computer Animation Ying Zhu Georgia State University
Understanding an App’s Architecture
Projectiles in Unreal Engine 4
Collision Detection, Prefabs
lecture 8 Our First Project
A Prime Example of HCI Application
Creating & Using Sprites Adding Colliders
Blender API: Part 2: Game Engine
Week 6: Time and triggers!
Motion in Real and Virtual Worlds
Computer Animation Algorithms and Techniques
Fundaments of Game Design
Advanced Games Development Game Physics
Resources and interactions
CSC 221: Introduction to Programming Fall 2018
GPAT – Chapter 7 Physics.
Presentation transcript:

UFCEKU-20-3Web Games Programming Unity 3D Physics Colliders and Object Collisions

UFCEKU-20-3Web Games Programming Agenda The Unity ‘Physics Engine’ Creating and Using ‘Colliders’ Using Colliders as 'Triggers’ for Events Updating World Objects via Collision and Trigger Events

UFCEKU-20-3Web Games Programming The Unity Physics Engine Unity contains the powerful NVIDIA PhysX Physics Engine The physics engine provides realistic ‘motion under gravity’ characteristics when applied to objects in the 3D environment friction, acceleration, collision reactions based on the chosen physics material, metal, wood, rubber, elastic etc. The physics engine also provides basic collision detection between objects via ‘Colliders’ Objects created in Unity usually have a default collider created when the object is created – e.g. a sphere object would be created with a sphere collider. Objects imported as models would require an appropriate collider to be chosen.

UFCEKU-20-3Web Games Programming Collision Detection Detect when an world object or element has made contact with another world object or element Collision with world boundaries e.g. terrain Player collides with world object Player acquires a resource Collisions must be accurately detected Collision events must be handled by system logic World state changed to reflect changes made by collisions – update values, acquire energy, add time bonus, communicate with other objects via scripts etc.

UFCEKU-20-3Web Games Programming 2D Sprite Collisions

UFCEKU-20-3Web Games Programming 2D Sprite Bounding Boxes

UFCEKU-20-3Web Games Programming False Collisions Sprite boundaries overlap but sprites not colliding

UFCEKU-20-3Web Games Programming Collision Detection for 3D Some 3D scenarios may use bounding spheres A bounding sphere is a hypothetical sphere that completely encompasses an object. For finer-grain collision detection several spheres could be used on a single object Each would need to be coded to see if a collision had occurred Most 3D APIs provide some functional collision detection.

UFCEKU-20-3Web Games Programming Physics ‘Colliders’ in Unity 3D When choosing colliders there is a need to take account of the accuracy of collision detection required versus the computational impact of the chosen collider. A box collider would use much less computation than a mesh collider Unity also provides a capsule collider, which is the default collider for a First Person Controller.

UFCEKU-20-3Web Games Programming Example Colliders: Box Cube Box Collider

UFCEKU-20-3Web Games Programming Example Colliders: Sphere Cube Sphere Collider

UFCEKU-20-3Web Games Programming Example Colliders: Capsule Cube Capsule Collider

UFCEKU-20-3Web Games Programming Example Colliders: Mesh Cube Mesh Collider

UFCEKU-20-3Web Games Programming Example Colliders: False Collisions Cube Collider on Sphere False Collision

UFCEKU-20-3Web Games Programming Example Colliders: Imported Models Model in Maya

UFCEKU-20-3Web Games Programming Example Colliders: Models Box on MeshCapsule on MeshMesh on Mesh

UFCEKU-20-3Web Games Programming Using Colliders as ‘Colliders’ The default setting for any collider attached to an object is to restrict the object being passed through be other world objects. The collision event must be handled by a script attached to one or both of the objects involved in the collision ObjectCollisons.js Code to handle collisions

UFCEKU-20-3Web Games Programming Handling Events Initiated by Collisions This function is attached to the First Person Controller (Capsule Collider) function OnControllerColliderHit(hit:ControllerColliderHit){ if (hit.collider == GameObject.Find("RedSphere").collider){ Debug.Log("I've hit the Red Sphere"); }; if (hit.collider == GameObject.Find("BlueSphere").collider){ Debug.Log("I've hit the Blue Sphere"); }; Unity has a built in function for detecting collisions:

UFCEKU-20-3Web Games Programming Tag Names and the Tag Manager To reference objects in the collision function each object must have a name (Tag) defined via the Tag Manager The tag name used in any script reference must exactly match the tag name defined in the Tag Manager So RedSphere is not the same as redSphere

UFCEKU-20-3Web Games Programming Tag Manager Window RedSphere named in Tag Manager Element Slot

UFCEKU-20-3Web Games Programming Using Colliders as ‘Triggers’ Object collisions may be used to generate events ‘triggers’ which can be used to update logic in the World, generate actions, instantiate (create) new objects or remove unwanted objects from the world. Using triggers is one way for the player to collect items that update values via attached scripts. ObjectTriggers.js Code to handle collisions as event triggers. Objects defined as triggers can be ‘passed through’ by other objects

UFCEKU-20-3Web Games Programming Handling Events Initiated by Triggers This function is attached to the First Person Controller (Capsule Collider) function OnTriggerEnter(collisionInfo:Collider){ if(collisionInfo.gameObject.tag == "RedSphere"){ Debug.Log("I've gone through the Red Sphere!"); } if(collisionInfo.gameObject.tag == "BlueSphere"){ Debug.Log("I've deleted the Blue Sphere!"); Destroy(collisionInfo.gameObject); } Unity has a built in function for detecting collisions as triggers:

UFCEKU-20-3Web Games Programming Summary Unity has a built-in Physics Engine that provides ‘motion-under-gravity’ properties and behaviors for objects with attached physics components Basic collision detection is also provided by several default colliders such as Box and Capsule for objects created in Unity. Models with more complex mesh topology must have colliders selected to suit their purpose while considering the computational impact on system performance. Unity provides basic functions to detect and handle collision events for both collision reactions and triggers events. World objects must be named in the Tag Manager for associated scripts to reference object names accordingly. Tag names are case sensitive and must exactly match their corresponding script references.