TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

Unity Understanding Collisions

Unity Understanding Collisions with Introduction, Installing, GameObject, First Unity Project, Unity 2D, Sprite Unity, Loops, If Statement, Data Types, Swith Statements, Unity UI, Unity Asset Store etc.

<< Back to UNITY

Understanding Collisions

As you know, everything in your game is a GameObject. Even the individual tiles that make up your level are GameObjects by themselves.

When we consider every component as a GameObject, we understand that there could be thousands of GameObjects in a scene, interacting with each other in some way. You can visualize that if unity added collisions to every single GameObject, it would be impractical for the engine to calculate collisions for every single one of them.

In Unity, collisions are separated from the actual sprite itself, attached as separate components, and are calculated on their own.

Collider components describe the shape of an object for the purposes of physical collisions. A collider will be invisible and is required to be the exact same shape as the GameObject's mesh.

Let's add a simple wall that our player can collide against. First of all, create a sprite. To do that, right click on your scene from the Hierarchy tab and select 2D object -> Sprite.

Understanding Collisions

Rename the New Sprite to Player.

Or directly go to the project tab and right click on Assets and select Create -> Sprites -> Square.

Understanding Collisions

Drag that square to the scene.

Understanding Collisions

Now go to Add Component in the Inspector tab, and search for "Box Collider 2D".

Understanding Collisions

You will see a bright green line on the perimeter of your Player GameObject. This is the collision boundary. It defines the actual shape of the collidable object.

Understanding Collisions

We can create collisions of different shapes in different sizes. They can be in a rectangular shape, or even they can be in polygonal shapes.






Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf