Download presentation
Presentation is loading. Please wait.
Published byIsabel Phelps Modified over 9 years ago
1
Done already for your convenience! Telerik School Academy http://academy.telerik.com Unity 2D Game Development
2
1. 2D Physics Overview 2. RigidBody 2D 3. Colliders 2D 1.Circle Collider 2D 2.Box Collider 2D 3.Polygon Collider 2D 4.Edge Collider 2D 4. Forces 2
3
Rigidbodies, Colliders, Joints, etc.
4
All physics elements are normal components Just add them to a game object Set all needed properties The physics engine will start using them Enjoy the effects Enjoy the effects 4
5
Rigidbodies Rigidbodies Main component for the Physics Engine to start With Rigidbody the object will start to respond to gravity If you enable Rigidbody, you should not try to change the Transform part of the object Instead, you should apply forces and let the engine do the heavy lifting If you need non-moving by the engine Rigidbody, check “Is Kinematic” option 5
6
Colliders Colliders Define the shape of an object in terms of physical collisions Most of the time invisible Use Box Collider and Circle Collider whenever possible for performance reasons Otherwise use Polygon Collider Colliders with Rididbody are dynamic colliders Colliders without Rigidbody are the static environment in your game – walls, floor, etc. 6
7
Physic Materials Physic Materials Physic Materials Materials define the physics collision effect For example – ice is slippery, rubber has friction Usually parameters are found by trial-error In 2D there are two parameters Friction – friction coefficient Bounciness – the degree to which collisions rebound from the surface 0 – no bounce effect 1 – full bounce effect with no loss of energy 7
8
Joints Joints Attaching two rigidbodies to a fixed point Allow restricted movement Rotation by the three axes Translation by the three axes Stretching like a spring You can set joint to break if certain force is applied 8
9
Different Types of Colliders Trigger Collider – does not respond to physics calculations but sends event to which you can subscribe from the scripts OnCollisionEnter2D / OnTriggerEnter2D – when two colliders starts colliding for the first time OnCollisionStay2D / OnTriggerStay2D – when two colliders are colliding OnCollisionExit2D / OnTriggerExit2D – when colliders are no longer colliding Simply select “Is Trigger” 9
10
Different Types of Colliders Static Collider – object with collider but no Rigidbody Used for level geometry and should never move Should not be disabled or enabled If you do, major performance decrease may occur Also – calculation errors in the engine may occur If you want to alter it – add Rigidbody to it 10
11
Different Types of Colliders Rigidbody Collider – object with collider and Rigidbody Most common case Fully simulated by the physics engine Reacts to collisions Reacts to forces from script Collide with all other objects 11
12
Different Types of Colliders Kinematic Rigidbody Collider – object with collider and Kinematic Rigidbody Has “Is Kinematic” property set Does not react to collisions and forces from the engine Should be moved by a script They behave like static colliders but can be enabled/disabled/moved when needed 12
13
How to use it?
14
Rigidbody 2D Rigidbody 2D Rigidbody 2D Attach it to objects controlled by the physics In 2D only the XY plane takes effect for translation and the Z axis for rotation 14
15
Properties of RidigBody 2D Mass – mass of the object Linear Drag / Angular Drag – coefficient for movements Gravity Scale – whether the gravity should be more or less on this object Fixed Angle – can be rotated or not? Is Kinematic – is the body moved by forces and collisions 15
16
How to use it?
17
Box Collider 2D Box Collider 2D Box Collider 2D Rectangular shaped collider Attached to an game object With or without a sprite 17
18
Properties of Box Collider 2D Material – the material to use for the collider Is Trigger – whether events should be sent Offset – local offset of the collider geometry Size – the size of the rectangular shape 18
19
How to use it?
20
Circle Collider 2D Circle Collider 2D Circle Collider 2D Circular shaped collider Attached to an game object With or without a sprite 20
21
Properties of Circle Collider 2D Material – the material to use for the collider Is Trigger – whether events should be sent Offset – local offset of the collider geometry Radius – the radius of the circular shape 21
22
How to use them?
23
Polygon Collider 2D and Edge Collider 2D Polygon Collider 2DEdge Collider 2D Polygon Collider 2DEdge Collider 2D Complex shaped collider Attached to an game object With or without a sprite Difficult to compute – performance impact 23
24
Properties of Polygon Collider 2D and Circle Collider 2D Material – the material to use for the collider Is Trigger – whether events should be sent Offset – local offset of the collider geometry 24
25
How to use them?
26
Two types of forces Constant Force 2D Constant Force 2D Constant Force 2D Effectors (Area Effector 2D for example) Area Effector 2DArea Effector 2D They both are added to a Rigidbody 2D Applied every Update of the game Good for in-game mechanics Have acceleration options 26
27
Rigidbody – component used by the physics engine for calculations Colliders – components to register any colliding objects in the game Different types of colliders – static, kinematic, etc. Other physics elements – joint, forces, etc. 27
28
форум програмиране, форум уеб дизайн курсове и уроци по програмиране, уеб дизайн – безплатно програмиране за деца – безплатни курсове и уроци безплатен SEO курс - оптимизация за търсачки уроци по уеб дизайн, HTML, CSS, JavaScript, Photoshop уроци по програмиране и уеб дизайн за ученици ASP.NET MVC курс – HTML, SQL, C#,.NET, ASP.NET MVC безплатен курс "Разработка на софтуер в cloud среда" BG Coder - онлайн състезателна система - online judge курсове и уроци по програмиране, книги – безплатно от Наков безплатен курс "Качествен програмен код" алго академия – състезателно програмиране, състезания ASP.NET курс - уеб програмиране, бази данни, C#,.NET, ASP.NET курсове и уроци по програмиране – Телерик академия курс мобилни приложения с iPhone, Android, WP7, PhoneGap free C# book, безплатна книга C#, книга Java, книга C# Николай Костов - блог за програмиране http://academy.telerik.com
29
C# Programming @ Telerik Academy csharpfundamentals.telerik.com csharpfundamentals.telerik.com Telerik Software Academy academy.telerik.com academy.telerik.com Telerik Academy @ Facebook facebook.com/TelerikAcademy facebook.com/TelerikAcademy Telerik Software Academy Forums forums.academy.telerik.com forums.academy.telerik.com
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.