Rigidbody and Collider Concepts in Unity

 

Hello everyone,

Today, I wanted to explain two concepts that should be learnt in the first place when starting Unity to new game development friends like me. After opening an empty project and adding that famous cube (in all the tutorials I saw, the teaching started by adding a cube :), the first thing to do is usually adding Rigidbody to the cube. So let’s start with this.

What is Rigidbody?

What is Rigidbody? Let’s examine this under this title. Rigidbody is a component used in Unity to give an object physical behaviour. Adding a Rigidbody to an object means allowing that object to be managed by the physics engine. So what is a physics engine? The physics engine simulates the movement and interaction of game objects in the physical world. This ensures that the object has physical properties such as mass, gravity, speed, force, and moves in accordance with the laws of physics. It also allows realistic motion and collision calculations. So it is very necessary for games.

What are the Basic Properties of Rigidbody?

Let’s examine the basic properties that appear in the inspector window when we add Rigidbody.

Rigidbody Inspector
  • Mass: Determines the mass of the object. Mass affects the resistance of the object against forces. Since the value we will write here means the mass of the object, objects with higher mass require more force.
  • Drag (Friction): It is the resistance force against the movement of the object. The higher the value we write here, the slower the object moves.
  • Angular Drag (Angular Friction): It is the resistance force against the rotational movement of the object.
  • Use Gravity: Enabling this option will cause the object to be under the influence of gravity, and if it is high up, it will fall downwards when the game is started. If there is no object to stop it when it falls, it will disappear from the game scene, but its presence will remain in the game system.
  • Is Kinematic: When this option is enabled, the object is not affected by the physics engine, but can move when it hits other objects. Kinematic objects are usually controlled programmatically.

What can we do using rigidbody?

Under this heading, let’s examine what we can do using the rigidbody feature.

  • Moving objects by applying force and torque. Thanks to this application, objects can fall faster, roll when falling or different reactions can occur.
  • Letting objects free fall. An object positioned higher than the ground can fall downwards when the game is started and stop when it hits the ground, or if the ground does not have a collider feature, it can pass through the ground and continue travelling in space.
  • Setting objects to react physically after collision. Post-collision disappearance function or any animation and effect can be added.

What is Collider?

Another feature that has been used in Unity since the beginning is collider. It is a component used to determine the presence of an object in the physical world. It can be called like a 3D frame placed around it. Adding Collider to an object allows that object to react to collisions. The Collider component can be of various types depending on the shape of the object. Now let’s look at which types it can be according to its shape.

What are Collider Types?

  • Box Collider: It is used for rectangular prism-shaped objects. It has a simple box shape.
  • Sphere Collider: Used for sphere-shaped objects.
  • Capsule Collider: Used for objects in the shape of a capsule (two hemispheres and a cylinder).
  • Mesh Collider: Used for complex shaped objects. It creates the collision area using the mesh structure of the object. Generally suitable for static (stationary) objects.
  • Terrain Collider: Used for terrain objects.

What are the Basic Properties of Collider?

Let’s examine the basic properties that appear in the inspector window when we add the Collider.

Collider Inspector
  • Is Trigger: When this option is enabled, Collider acts as a trigger instead of a collision. It initiates trigger events instead of physically interacting with other objects.
  • Material: A Physic Material is used to add physical properties to the Collider. This determines properties such as friction and flexibility.

What can we do using Collider?

Under this heading, let’s examine what we can do using the collider feature.

  • We can make objects collide with each other and give physical reactions. For example, when there is a collision, the objects go back separately or an animation like an explosion effect.
  • Enabling objects to initiate trigger events when they enter certain areas. For example, making an object disappear when it enters the collider area of another object.

Since we know both components separately, let’s finally examine how they can be used together.

Using Rigidbody and Collider Together

Adding both Rigidbody and Collider to an object allows us to fully manage the object’s interactions in the physical world. Since this management is a very important part of the game development process, learning these two components can make us a better game developer to begin with.

Rigidbody manages the physical movements and forces of the object, while Collider manages the collisions and trigger events of the object with other objects.

For example, let’s take a ball dropping and rolling on the ground in a game scene:

    • By adding a Rigidbody to the ball, we can ensure that it remains under the influence of gravity and moves with physical forces, i.e. rolls realistically.
  • At the same time, by adding a Sphere Collider to the ball, we can manage its collisions with other objects and add an effect or other triggered event.

In this way, the Rigidbody and Collider components work together to realistically simulate the physical behaviour and interactions of the object.

In this article, I tried to explain the importance of Rigidbody and Collider by talking about what it is. I hope it was useful.

Good coding to everyone.

Selin.

Unity’de Rigidbody ve Collider Kavramları

 

Herkese merhaba,

Bugün benim gibi oyun geliştirmeye yeni girişmiş arkadaşlara Unity’ye başlarken ilk sıralarda öğrenilmesi gereken iki kavramı olanca basitliğiyle anlatmak istedim. Boş bir proje açıp o meşhur küpü (gördüğüm tüm eğitimlerin genelinde öğretime küp eklenerek başlanıyordu :) ekledikten sonra yapılan ilk şey genelde küpe Rigidbody eklemek oluyor. Bu yüzden bununla başlayalım.

Rigidbody Nedir?

Rigidbody nedir? Bunu bu başlık altında inceleyelim. Rigidbody Unity’de bir nesneye fiziksel davranışlar kazandırmak için kullanılan bir bileşen. Bir nesneye Rigidbody eklemek, o nesnenin fizik motoru tarafından yönetilmesini sağlamak demek. Peki fizik motoru ne? Fizik motoru, oyun nesnelerinin fiziksel dünyadaki hareketlerini ve etkileşimlerini simüle ediyor. Bu da nesnenin kütle, yerçekimi, hız, kuvvet gibi fiziksel özelliklere sahip olmasını ve fizik kurallarına uygun hareket etmesini sağlar. Aynı zamanda gerçekçi hareket ve çarpışma hesaplamaları yapma olanağı sağlıyor. Yani oyunlar için çok lazım.

Rigidbody’nin Temel Özellikleri Neler?

Rigidbody’yi eklediğimizde inspector penceresinde görünen temel özelliklerini inceleyelim.

Rigidbody Inspector
  • Mass (Kütle): Nesnenin kütlesini belirler. Kütle, nesnenin kuvvetlere karşı gösterdiği direnci etkiler. Buraya yazacağımız değer nesnenin kütlesi demek olduğundan, daha yüksek kütleli nesneler, daha fazla kuvvet gerektirir.
  • Drag (Sürtünme): Nesnenin hareketine karşı olan direnç kuvvetidir. Buraya yazacağımız değer ne kadar yüksek olursa, nesne o kadar daha yavaş hareket eder.
  • Angular Drag (Açısal Sürtünme): Nesnenin dönüş hareketine karşı olan direnç kuvvetidir.
  • Use Gravity (Yerçekimi Kullan): Bu seçeneği etkinleştirmek, nesnenin yerçekimi etkisi altında kalmasını, eğer yüksekteyse oyun başlatıldığında aşağı doğru düşmesini sağlar. Düştüğünde durabileceği bir nesne bulunmuyorsa oyun sahnesinde gözden kaybolur ancak varlığı oyunun sisteminde bulunmaya devam eder.
  • Is Kinematic: Bu seçenek etkinleştirildiğinde, nesne fizik motoru tarafından etkilenmez, ancak diğer nesnelere çarptığında hareket edebilir. Kinematic nesneler genellikle programatik olarak kontrol edilir.

Rigidbody kullanarak neler yapabiliriz?

Bu başlık altında rigidbody özelliği kullanarak neler yapabiliriz, bunu inceleyelim.

  • Kuvvet ve tork uygulayarak nesneleri hareket ettirmek. Bu uygulama sayesinde nesneler daha hızlı düşebilir, düştüğünde yuvarlanma veya daha farklı tepkiler oluşabilir.
  • Nesneleri serbest düşüşe bırakmak. Zeminden daha yukarıda konumlandırılmış bir nesne oyun başlatıldığında aşağı doğru düşerek zemine çarptığında durabilir veya zeminin bir collider özelliği yok ise zemin içerisinden geçip boşlukta yolculuk etmeye devam edebilir.
  • Nesneleri çarpışma sonrası fiziksel tepkiler verecek şekilde ayarlamak. Çarpışma sonrası yok olma fonksiyonu veya herhangi bir animasyon ile efekt eklenmesi sağlanabilir.

Collider Nedir?

Unity’de ilk başlardan itibaren en çok kullanılan bir diğer özellikse collider. O da bir nesnenin fiziksel dünyadaki varlığını belirlemek için kullanılan bir bileşen. Etrafına konan 3 boyutlu çerçeve gibi denebilir. Bir nesneye Collider eklemek, o nesnenin çarpışmalara tepki verebilmesini sağlar. Collider bileşeni, nesnenin şekline bağlı olarak çeşitli türlerde olabilir. Şimdi şekillerine göre hangi türlerde olabilir, buna bakalım.

Collider Türleri Nelerdir?

  1. Box Collider: Dikdörtgen prizma şeklindeki nesneler için kullanılır. Basit kutu şekline sahiptir.
  2. Sphere Collider: Küre şeklindeki nesneler için kullanılır.
  3. Capsule Collider: Kapsül (iki yarım küre ve silindir) şeklindeki nesneler için kullanılır.
  4. Mesh Collider: Karmaşık şekilli nesneler için kullanılır. Nesnenin mesh (ağ) yapısını kullanarak çarpışma alanını oluşturur. Genellikle statik (hareketsiz) nesneler için uygundur.
  5. Terrain Collider: Arazi nesneleri için kullanılır.

Collider’ın Temel Özellikleri Nelerdir?

Collider’ı eklediğimizde inspector penceresinde görünen temel özelliklerini inceleyelim.

Collider Inspector
  • Is Trigger: Bu seçenek etkinleştirildiğinde, Collider çarpışma yerine tetikleyici olarak davranır. Diğer nesnelerle fiziksel etkileşime girmek yerine tetikleme olaylarını başlatır.
  • Material: Collider’a fiziksel özellikler eklemek için bir Physic Material kullanılır. Bu, sürtünme ve esneklik gibi özellikleri belirler.

Collider kullanarak neler yapabiliriz?

Bu başlık altında collider özelliği kullanarak neler yapabiliriz, bunu inceleyelim.

  • Nesnelerin birbirine çarpmasını ve fiziksel tepkiler vermesini sağlayabiliriz. Örneğin çarpışma olduğunda nesnelerin ayrı ayrı geri gitmesi ya da patlama efekti gibi bir animasyon çalışması.
  • Nesnelerin belirli alanlara girdiğinde tetikleyici olaylar başlatmasını sağlamak. Örneğin bir nesne diğer bir nesnenin collider alanına girdiğinde yok olmasını sağlamak gibi.

Her iki bileşeni de ayrı ayrı tanıdığımıza göre birlikte kullanımları nasıl olur, son olarak bunu inceleyelim.

Rigidbody ve Collider’ın Birlikte Kullanımı

Bir nesneye hem Rigidbody hem de Collider eklemek, nesnenin fiziksel dünyadaki etkileşimlerini tam anlamıyla yönetmemizi sağlar. Bu yönetim oyun geliştirme sürecinin çok önemli bir parçası olduğu için bu iki bileşeni öğrenmek bizi başlangıç için daha iyi bir oyun geliştiricisi yapabilir.

Rigidbody, nesnenin fiziksel hareketlerini ve kuvvetlerini yönetirken, Collider, nesnenin diğer nesnelerle çarpışmalarını ve tetikleyici olaylarını yönetir.

Örneğin, bir oyun sahnesinde bir topun yere düşmesini ve yuvarlanmasını ele alalım:

  • Topa bir Rigidbody ekleyerek onun yerçekimi etkisi altında kalmasını ve fiziksel kuvvetlerle hareket etmesini yani gerçekçi bir şekilde yuvarlanmasını sağlayabiliriz.
  • Aynı zamanda topa bir Sphere Collider ekleyerek onun diğer nesnelerle çarpışmalarını yönetir, varsa efekt veya tetiklenen başka bir olay ekleyebiliriz.

Bu şekilde, Rigidbody ve Collider bileşenleri birlikte çalışarak nesnenin fiziksel davranışlarını ve etkileşimlerini gerçekçi bir şekilde simüle eder.

Bu yazımda sizlere Rigidbody ve Collider’ın ne olduğundan bahsederek önemini anlatmaya çalıştım. Umarım faydalı olmuştur.

Herkese iyi kodlamalar.

Selin.

Flutter and Rivals

 Hello, today I would like to talk about what could be used instead of Flutter if Flutter did not exist, or about multi-platform supporting technologies and software languages that could be an alternative to Flutter as it is today. In my opinion, there is no technology or software language that will completely “destroy” Flutter yet. However, there are always innovations and developments in the software world, it is not possible to prevent this. Instead, what might happen is this: the popularity and use of a technology depends on many factors, so as new technologies emerge, some may replace existing ones. Today, I’m going to talk briefly about some of the most commonly compared technologies that compete with Flutter.

1. React Native

I think React Native should be the most compared framework with Flutter. Especially in terms of performance and developer experience, I often come across comparisons.

  • While Flutter is a framework supported by Google, React Native is known for being developed and supported by Facebook.
  • It allows developing mobile applications using Javascript and React.
  • Like Flutter, it has a very large community, and sometimes there are even comparisons between communities about which one is more numerous.
  • React Native also has reusable components like Flutter. In other words, you can write once during the software development process and then use it over and over again even in different projects. Thus, you can develop more efficient, consistent and easy-to-maintain projects.
  • Since React is web development based, it is much easier for web developers to adapt to React Native than Flutter. This may be one of the important reasons why it is preferred.

2. Kotlin Multiplatform Mobile (KMM)

KMM is developed and supported by Jetbrains. Again, you can write and publish on multiple platforms with the same code base and common business logic.

  • Unlike Flutter and React Native, you can also make different and platform-specific coding for Android or iOS. If you ask where is the advantage of coding differently when you can run it on both sides with a single code, you can take advantage of the unique features and APIs of both platforms.
  • KMM is written in Kotlin, a modern and open source language. The powerful features of this language contribute to the developer experience.
  • As for the competition, since KMM is still a developing technology, some libraries and community support are not as advanced as others.

3. Xamarin

Xamarin is an open source platform developed and supported by Microsoft. You can develop cross-platform mobile and Windows applications using C# and .NET.

  • Like others, you can develop with a single code base. You can also share business logic and data models. Thus, it contributes to the development of fast and easy-to-maintain projects.
  • Since .NET is a well-established and established ecosystem, it has a good integration with it and has a wide range of development tools.
  • Xamarin offers platform-specific performance as it provides direct access to native APIs. It also uses native UI components for Android and iOS.
  • Since it has been on the market for a long time and is supported by Microsoft, it has a large community and extensive documentation.
  • The disadvantage for this platform is that it usually reaches larger file sizes.

As a result, although I am working with Flutter myself and still learning, I wanted to briefly summarise the technology and platforms that can be an alternative to Flutter for you. I hope I have been inspiring at some point in your work.

Have a good work.

Selin.

Flutter ve Rekabet

 Merhaba, bugün sizlere Flutter olmasaydı yerine neler kullanılabilirdi veya bugünkü haliyle Flutter’a alternatif olabilecek çoklu platform destekleyen teknoloji ve yazılım dillerinden bahsetmek istiyorum. Benim görüşüme göre, Flutter’ı tamamiyle “yok edecek” bir teknoloji veya yazılım dili henüz yok. Ancak yazılım dünyasında her zaman yenilikler ve gelişmeler oluyor, bunun önüne geçmek mümkün değil. Bunun yerine, şu olabilir: bir teknolojinin popülerliği ve kullanımı birçok faktöre bağlı dolayısıyla yeni teknolojiler ortaya çıktıkça bazıları mevcut olanların yerini alabilir. Ben bugün sizlere Flutter ile rekabet eden, karşılaştırması en çok yapılan teknolojilerden kısaca bahsedeceğim.

1. React Native

Sanırım Flutter ile en çok karşılaştırması yapılan framework React Native olsa gerek. Özellikle performans ve geliştirici deneyimi açısından mukayese edildiğine çok sıklıkla rastlıyorum.

  • Flutter Google tarafından desteklenen bir framework iken React Native Facebook tarafından geliştirilip desteklenmesiyle biliniyor.
  • Javascript ve React kullanarak mobil uygulamalar geliştirmeye olanak tanıyor.
  • Flutter gibi çok geniş bir topluluğa sahip, hatta bazen topluluklar arası hangisinin sayıca daha çok olduğuna dair karşılaştırmalar bile söz konusu olabiliyor.
  • React Native de Flutter gibi yeniden kullanılabilen bileşenlere (reusable components) sahip. Yani yazılım geliştirme sürecinde bir kez yazıp sonrasında farklı projelerde bile tekrar tekrar kullanabiliyorsunuz. Böylelikle daha verimli, tutarlı ve bakımı kolay projeler geliştirebiliyorsunuz.
  • React web geliştirme tabanlı olduğundan, web geliştiricilerin React Native’e adapte olması Flutter’a göre çok daha kolay. Tercih edilmesinin önemli sebeplerinden biri bu olabilir.

2. Kotlin Multiplatform Mobile (KMM)

KMM Jetbrains tarafından geliştirilip destekleniyor. Yine birden fazla platformda aynı kod tabanı ve ortak iş mantığı ile yazıp yayınlayabiliyorsunuz.

  • Flutter ve React Native’den farklı olarak isterseniz Android ya da iOS için farklı ve platforma özgü kodlama da yapabiliyorsunuz. Tek kodla iki tarafta da çalıştırmak varken, farklı kodlamanın avantajı nerede diye soracak olursanız, bu sayede, her iki platformun kendine özgü özelliklerinden ve API’lerinden faydalanabiliyorsunuz.
  • KMM, modern ve açık kaynaklı bir dil olan Kotlin ile yazılıyor. Bu dilin güçlü özellikleri geliştirici deneyimine katkı sağlıyor.
  • Rekabet kısmına gelirsek, KMM halen gelişmekte olan bir teknoloji olduğu için bazı kütüphaneleri ve topluluk desteği diğerleri kadar gelişmiş değil.

3. Xamarin

Xamarin Microsoft tarafından geliştirilip desteklenen açık kaynaklı bir platform. Çapraz platform mobil ve Windows uygulamalarını C# ve .NET kullanarak geliştirebiliyorsunuz.

  • Diğerleri gibi tek bir kod tabanıyla geliştirme yapabiliyorsunuz. İş mantığını, veri modellerini de paylaşabiliyorsunuz. Böylelikle hızlı ve bakımı kolay projeler geliştirebilmenize katkı sağlamış oluyor.
  • .NET köklü ve yerleşik bir ekosistem olduğundan bununla iyi bir entegrasyona sahip ve geniş kapsamlı geliştirme araçları mevcut.
  • Xamarin yerel API’lere doğrudan erişim sağladığından platforma özgü performans sunuyor. Ayrıca Android ve iOS için yerel UI bileşenleri kullanıyor.
  • Uzun süredir piyasada ve Microsoft tarafından desteklendiği için de geniş bir topluluk ve kapsamlı dokümantasyonu bulunuyor.
  • Genellikle daha büyük dosya boyutlarına ulaşması bu platform için bir dezavantaj.

Sonuç olarak kendim Flutter ile çalışıyor ve halen öğreniyor olsam da, sizler için Flutter’a alternatif olabilecek teknoloji ve platformları sizler için araştırdım, kısaca özetlemek istedim. Umarım çalışmalarınızın bir noktasında ilham verici olmuşumdur.

İyi çalışmalar.

Selin.