Şimdi Ara

Unity, AddForce hakkında

Daha Fazla
Bu Konudaki Kullanıcılar: Daha Az
2 Misafir - 2 Masaüstü
5 sn
5
Cevap
1
Favori
2.755
Tıklama
Daha Fazla
İstatistik
  • Konu İstatistikleri Yükleniyor
1 oy
Öne Çıkar
Sayfa: 1
Giriş
Mesaj
  • Merhabalar. Kafama takılan şeyi bir örnekle sormak istiyorum.

    Mesela bir A objesi var ve ben bu objeye B noktasındaki objenin konumunun olduğu yöne doğru AddForce() ile 10 birimlik bir kuvvet uyguluyorum ve bunu da mouse'a her tıkladığımda gerçekleştiriyorum.

    Bunu yaptığımda A objesi B objesine yaklaştıkça (fareye her tıkladığımda) A'nın her tıklamada aldığı yol (yani uygulanan kuvvet) git gide azalıyor, hedefe yaklaştıkça baya bir yavaşlıyor.

    İşte ben bunun mantığını anlamadım, sebebi nedir?

    Velocity'de böyle bir şey yok.

    Hem İngilizce hem Türkçe olarak iki fonksiyonun da açıklamalarını okudum, araştırdım ama kafamda mantığını oturtamadım. Sebebi nedir?

    AddForce'ta yönü normalize edip yazsam da bir şey değişmiyor sonuç aynı. Ama Velocity'de normalize edip yazarsam istediğim gibi her tıklamada sabit frame ilerliyor. Normalize etmezsem velocity'de de yavaşlayarak ilerliyor.


    EDIT: Cevabı buldum. Belki benim gibi başka zaman merak edip, ihtiyacı olan olur diye aşağıya da bulduğum cevabı kopyalıyorum:

    Öncelikle kaynak:
    www.learnfreeprogramming.co
    Difference Between Rigidbody.velocity and Rigidbody.addforce in Unity
    http://www.learnfreeprogramming.co/2017/09/difference-between-rigidbodyvelocity.html


    quote:

    "Rigidbody Velocity and Rigidbody Addforce are two confusing functions in Unity 3D and often beginners fail to understand their difference. In This Article, I'm going to discuss the difference between RigidBody.velocity and RigidBody.addforce.


    In both cases, whether it is Addforce or velocity function I'm am going to use the term force to explain them.

    When you are using Rigidbody.velocity , then, in that case, you are adding force to your object but this force will only move the object unless and until we keep applying force.

    For example

    body.velocity= new Vector3(0,0,5);

    Let say you have added 5f in z position and that force will be added when you'll press W key.
    So When you will press W key the object will instantly start at the speed of 5. It's like the same if you are adding force using this function on a car, that car will start at the speed of 5.

    body.velocity= new Vector3(0,0,200);

    And if you let say change the value to 200 and then after saving press W. Car will start running at the speed of 200 from starting which is not possible in real world.

    Now If you talk about Rigidbody.addforce

    By Continuing our Car example. if you add the force of 200 to car

    body.addforce(0,0,200);

    The Car will not start moving at the speed of 200 if we press W but it starts from slow and then increases its speeds and stops according to the value of Drag.

    Rigidbody.addforce starts slow and then speed up, just like you are dragging a heavy table, first you will start pushing that table, the table will just move a little bit from its position but if you keep pushing that table it will starting moving & if you leave that table it will cover some distance depending on surface and that's the same rigidbody.addforce do.

    You can use Rigidbody.velocity where you just want to move your object to react instantly like player jump & the result of that force will vanish just after the jump and you can use Rigidbody.addforce where you need slow start and then the continuous movement like a rocket. If you use Rigidbody.addforce in jump , Player/Object will remain in space for a while and then will come back to ground .



    A guy has also explained on unity forums about this what he says read that

    First of all the difference is, rigidbody.velocity changes the velocity in an instant while AddForce applies force on an updated basis based on how you use it.

    For example, in real world, when you kick the football, you apply a force to it but, it's a big force so ball's Z velocity suddenly becomes let's say 10. So from 0 it becomes 10 and it moves forward really fast, getting slower in time because of the air drag. Same applies for the drinks a barman tosses on the bar like in the movies.

    When you push a very heavy create, you apply force to it constantly because it's very heavy and it has a bigger mass so it resists the force therefore moves slower. And you add more force constantly to move it somewhere.

    When an attack helicopter shoots rockets, those rockets always move with the same speed because they have a constant pushing power behind them, or the space shuttles once they are taking off. So they don't lose speed. it's constant force.

    So about which works best for which situations as it should be already clear from the above examples,

    -Constant force for objects which have their own pushing power like rockets.

    -Rigidbody.velocity for objects which have a big starting power then getting slower by drag, like football, thrown hand grenade, arrow etc. (I've also used this for making a jump pad. So that when player triggers the jump pad, players Y velocity suddenly becomes 10 so it jumps up getting slower in time)

    -AddForce for adding forces constantly, moving objects with force every frame. If you know Marble Blast game, that's how it works. Based on the player input, you add a force to the marble. So as long as forward button is held down, a force of for example 5 added to it in that direction."



    Türkçesi, uzun uzun çevirmeyeceğim kendi cümlelerimle özetlersem: velocity komutu ani veya anlık diyebileceğimiz sabit bir kuvvet uygulamamızı sağlar. 2 tane örnek verilmiş. Velocity için zıplama veya topa vurma; AddForce için ise ağır bir masayı ittirme veya arabayı hızlandırma.

    Siz mesela W tuşuna basıldığında gidecek olan bir araba yaptınız diyelim. Siz bu arabaya velocity ile 200 birimlik bir kuvvet uyguladınız diyelim. W tuşuna bastığınız anda araba birden 200 birim ileri ok gibi fırlayacak ve elinizi tuştan çektiğiniz anda ayarladığınız direnç (Drag, Türkçesi ile hava sürtünmesi de denebilir) etkisiyle yavaşlayıp duracak. Mantıken bu çok saçma bir durum. Bu örnekte AddForce kullanırsak, W tuşuna bastığımız anda araba 0'dan 200'e birden değil de yavaş yavaş ivmelenerek veyahut hızlanarak çıkacak ve siz elinizi W'den çekince de aynı oranda ve Drag değerine bağlı olarak yavaşlayıp duracak. İşte kısaca en basit örnekle böyle anlatılabilir aradaki farkları.

    AddForce için roketlerin ateşlenmesi de en iyi örneklerden biridir. Zaten bu komutun kendi içinde modları var, "impulse"(itki), "acceleration"(hızlanma) gibi, gibi.

    Velocity> Anlık tepkiler
    AddForce> Yavaş yavaş hızlanarak uygulanan kuvvetler.

    Ayrıca bir not daha söyleyeyim, GetAxis komutu da 0'dan 1 veya -1'e direk gelmez AddForce mantığı ile aynıdır, siz yukarı ok tuşuna bastığınızda mesela yavaşa 1 olur direk basar basmaz 1 olmaz bu da aklınızda bulunsun. "GetAxisRaw" komutunu kullanırsanız direk tuşa bastığınız anda 1 veya -1 olur değer.



    < Bu mesaj bu kişi tarafından değiştirildi Fulton -- 20 Nisan 2019; 18:56:27 >







  • EKLEME: Bahsettiğim fark şu tarz bir şey:

    Unity, AddForce hakkında

    Kodlar:

    Unity, AddForce hakkında


    Log çıktısında cisme her defasında aynı kuvvet uyguladığımda aldığı yol değişiyor. Aynı komutları rb.velocity ile yapınca log çıktısında sabit değer oluyor hep aldığı yol.

    Umarım anlatabilmişimdir.

    Ve ben cisme durduğu anda yani ilk hızı 0'ken kuvvet uyguluyorum.




  • Teşekkürler bilgilendirme için, aradığım bir cevap oldu.
  • addforce türkçesi kuvvet ekle
    addvelocity türkçesi hız ekle


    bir cisime hız eklerseniz anında o hıza ulaşır.
    ama bir cisme belirli bir yönde kuvet uygularsanız karşı yönde uygulanan direnci düştükten sonra. cisim kalan kuvvetin kütleye orantısıyla ivmelenir.

    Temel fizik bilgisiyle F= m x a burdaki f kuvvet m kütle a ise ivmedir. ivme cismin birim zamanda kazandığı hız miktarını gösterir.
  • Yapay Zeka’dan İlgili Konular
    Assassin's Creed ile ilgili
    11 yıl önce açıldı
    Daha Fazla Göster
    
Sayfa: 1
- x
Bildirim
mesajınız kopyalandı (ctrl+v) yapıştırmak istediğiniz yere yapıştırabilirsiniz.