- Unity - Using the Asset Store
- Unity - The Particle System
- Unity - Materials and Shaders
- Unity - The Slider
- Unity - Text Element
- Unity - The Button
- Unity - Starting with UI
- Unity - Introduction to Audio
- Unity - The Console
- Unity - Coroutines
- Unity - GameObject Destruction
- Understanding Prefabs and Instantiation
- Unity - Custom Collision Boundaries
- Unity - Rigidbodies and Physics
- Unity - Understanding Collisions
- Unity - Basic Movement Scripting
- Unity - Saving and Loading Scenes
- Unity - Internal Assets
- Transforms and Object Parenting
- Unity - Modifying Sprites
- Unity - Creating Sprites
- Unity - Installation and Setting Up
- Unity - Introduction
- Unity - Home
Unity Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Unity - Understanding Colpsions
Colpsions in Unity are separated from the actual Sprite itself, attached as separate components and are calculated on their own. Let us now learn the cause behind this.
Everything in your game is a GameObject. Even the inspanidual tiles that make up your level are GameObjects by themselves.
When we consider every component as a GameObject, we reapze that there could be thousands of GameObjects in a scene, interacting with each other in some way. You can imagine that if Unity added colpsions to every single GameObject, it would be impractical for the engine to calculate colpsions for every single one of them.
We will go ahead and add a simple “wall” that our player character can colpde against. To do so, create another sprite and scale it up using the Rect tool. We will also give it a red color through the Color property in the Sprite Renderer component.
Now, go to Add Component in the Inspector, and type in “Box Colpder 2D”. Cpck the first component that shows up, and a new component should appear.
You will see a bright green pne on the perimeter of your GameObject. This is the colpsion boundary. It is what defines the actual shape of the colpdable objects.
Repeat the same with our movable GameObject as well.
Of course, colpsions in Unity are not pmited to simply boxes. They can range in a variety of shapes and sizes, and are not necessarily reppcas of the object’s parameters.
They can also take on polygonal shapes.
It is not uncommon to see developers and designers use approximate shapes in their colpsion boundaries to simppfy their colpders and avoid unnecessary calculations for the engine. We will learn how to create different shapes and sizes with our colpders soon.
Now that we have our colpsion boundaries in place, hit play and see it in action.
You will notice that our movable object is not behaving normal. We will discuss the behaviour of the object in our subsequent chapter.
Advertisements