Upgrade to Pro — share decks privately, control downloads, hide ads and more …

【Unity道場京都スペシャル】プロが教える脱初心者スクリプト術!

unitydojo
November 05, 2016
2.8k

 【Unity道場京都スペシャル】プロが教える脱初心者スクリプト術!

unitydojo

November 05, 2016
Tweet

More Decks by unitydojo

Transcript

  1. COPYRIGHT 2016 @ UNITY TECHNOLOGIES JAPAN COPYRIGHT 2016 @ UNITY

    TECHNOLOGIES JAPAN ຊ೔ͷ͓͸ͳ͠ •ಈ͖Λ࡞ΔςΫχοΫ • ϓϥϯφʔɺΞʔςΟετ͞Μʹ΋໾ʹ ཱͭ΋ͷ
  2. COPYRIGHT 2016 @ UNITY TECHNOLOGIES JAPAN COPYRIGHT 2016 @ UNITY

    TECHNOLOGIES JAPAN ຊ೔ͷ͓͸ͳ͠ •࣮ԋ͋Γ •࣮ԋ಺༰΋ࢿྉʹೖΕͯ͋Δ •ϝϞΛऔΔඞཁ͸ͳ͠ʂ
  3. COPYRIGHT 2016 @ UNITY TECHNOLOGIES JAPAN COPYRIGHT 2016 @ UNITY

    TECHNOLOGIES JAPAN ຊ೔ͷ͓͸ͳ͠ •঺հ͢ΔϓϩάϥϜ͸ͱͯ΋γϯϓϧ • ॲཧΛྻڍ͢Δ͚ͩ • if จ͢Βॻ͔ͳ͍
  4. COPYRIGHT 2016 @ UNITY TECHNOLOGIES JAPAN COPYRIGHT 2016 @ UNITY

    TECHNOLOGIES JAPAN ຊ೔ͷ͓͸ͳ͠ •ʮ͋ͱͰ΍ͬͯΈΑ͏ʂʯ •ͱࢥͬͯ΋Β͑ΔΑ͏ʹ͕Μ͹Γ·͢ʂ
  5. COPYRIGHT 2016 @ UNITY TECHNOLOGIES JAPAN COPYRIGHT 2016 @ UNITY

    TECHNOLOGIES JAPAN ήʔϜ͕ಈͬͯ͘Ͳ͏͍͏͜ͱʁ ࣌ؒ ࡉ͔͍ॲཧΛ܁Γฦͯ͠ಈ͖Λ࡞͍ͬͯΔ ॲཧʢUpdateʣ ɾɾɾɾɾɾɾɾɾɾɾ
  6. COPYRIGHT 2016 @ UNITY TECHNOLOGIES JAPAN COPYRIGHT 2016 @ UNITY

    TECHNOLOGIES JAPAN Δtͱ͸ ࣌ؒ ͻͱͭͷॲཧʹ͔͚Δ͕࣌ؒΔt Δt
  7. COPYRIGHT 2016 @ UNITY TECHNOLOGIES JAPAN COPYRIGHT 2016 @ UNITY

    TECHNOLOGIES JAPAN Δtͱ͸ ࣌ؒ ͻͱͭͷॲཧΛ̍ϑϨʔϜͱݺͿ Δt
  8. COPYRIGHT 2016 @ UNITY TECHNOLOGIES JAPAN COPYRIGHT 2016 @ UNITY

    TECHNOLOGIES JAPAN Δtͱ͸ ඵؒ20ϑϨʔϜͷ৔߹ Δt 1ඵ 20ϑϨʔϜ
  9. COPYRIGHT 2016 @ UNITY TECHNOLOGIES JAPAN COPYRIGHT 2016 @ UNITY

    TECHNOLOGIES JAPAN Δtͱ͸ Δtͷฏۉ͸1/20ඵ Δt 1ඵ 20ϑϨʔϜ
  10. COPYRIGHT 2016 @ UNITY TECHNOLOGIES JAPAN COPYRIGHT 2016 @ UNITY

    TECHNOLOGIES JAPAN Δtͱ͸ ͭ·ΓɺΔt͸ඵؒϑϨʔϜ਺ͷٯ਺ Δt 1ඵ 20ϑϨʔϜ
  11. COPYRIGHT 2016 @ UNITY TECHNOLOGIES JAPAN ʲ֮ॻʳ Update ͸̍ඵؒʹԿճݺ͹ΕΔ͔Θ͔Βͳ͍ʢੑೳ͕௿͍؀ڥͩͱ গͳ͘ͳΔʣ

    →FixedUpdate ͸̍ඵؒʹݺ͹ΕΔճ਺͕ݻఆ Time.deltaTime ͸มಈ͢Δʢಉ͡ϑϨʔϜ಺Ͱ͸ݻఆʣ →Time.fixedDeltaTime ͸஋͕ݻఆ FixedUpdate Λ࢖͏ͱγϯϓϧʹʂ Δt ͸ Time.fixedDeltaTime
  12. COPYRIGHT 2016 @ UNITY TECHNOLOGIES JAPAN COPYRIGHT 2016 @ UNITY

    TECHNOLOGIES JAPAN Ұఆͷ֎ྗΛՃ͑Δͱɺ͋Δ଎౓ʹऩଋ͢Δ v t
  13. COPYRIGHT 2016 @ UNITY TECHNOLOGIES JAPAN COPYRIGHT 2016 @ UNITY

    TECHNOLOGIES JAPAN ࠷ऴతͳ଎౓ɺͦΕ͕ऴ୺଎౓ v t
  14. COPYRIGHT 2016 @ UNITY TECHNOLOGIES JAPAN COPYRIGHT 2016 @ UNITY

    TECHNOLOGIES JAPAN ऴ୺଎౓Λࢉग़͢Δهࣄ͕͋Γ·ͨ͠ʂ
  15. COPYRIGHT 2016 @ UNITY TECHNOLOGIES JAPAN COPYRIGHT 2016 @ UNITY

    TECHNOLOGIES JAPAN ֎ྗɺ࣭ྔɺυϥοά͕༩͑ΒΕͨͱ͖ͷऴ୺଎౓ v’ m:࣭ྔ k:υϥοά F0:֎ྗ v’:ऴ୺଎౓
  16. COPYRIGHT 2016 @ UNITY TECHNOLOGIES JAPAN COPYRIGHT 2016 @ UNITY

    TECHNOLOGIES JAPAN ऴ୺଎౓ v’ ΛಘΔͨΊͷ֎ྗʢ୯ͳΔࣜͷมܗʣ m:࣭ྔ k:υϥοά F0:֎ྗ v’:ऴ୺଎౓
  17. COPYRIGHT 2016 @ UNITY TECHNOLOGIES JAPAN COPYRIGHT 2016 @ UNITY

    TECHNOLOGIES JAPAN όωͱ͸ɺڑ཭ʹൺྫ͢Δྗͷ͜ͱ ऑ͍ ڧ͍
  18. COPYRIGHT 2016 @ UNITY TECHNOLOGIES JAPAN COPYRIGHT 2016 @ UNITY

    TECHNOLOGIES JAPAN όωΛϓϩάϥϜͰॻ͘ void AddSpringForce(Vector3 target_position, float r) { var diff = target_position - transform.position; var force = diff * r; rigidbody_.AddForce(force); }
  19. COPYRIGHT 2016 @ UNITY TECHNOLOGIES JAPAN COPYRIGHT 2016 @ UNITY

    TECHNOLOGIES JAPAN Φʔόʔγϡʔτʢ໨ඪϙΠϯτΛ௨Γա͗Δʣ x t
  20. COPYRIGHT 2016 @ UNITY TECHNOLOGIES JAPAN COPYRIGHT 2016 @ UNITY

    TECHNOLOGIES JAPAN Φʔόʔγϡʔτ͠ͳ͍৚݅ m:࣭ྔ k:υϥοά r:όω܎਺
  21. COPYRIGHT 2016 @ UNITY TECHNOLOGIES JAPAN COPYRIGHT 2016 @ UNITY

    TECHNOLOGIES JAPAN ֎ੵͱ͸ɾɾɾ •֎ੵͷ݁Ռ͸ϕΫτϧʂ •AxB ͱදه͢Δʢ͜ͱ͕ଟ͍ʣ •x͔ͩΒΫϩεੵͱ΋ݺͿɻӳޠͰݴ͏ͱ cross product •Unity Ͱ͸ Vector3.Cross ͱ͍͏ؔ਺ •var C = Vector3.Cross(A, B); ͱॻ͘ͱɺ ϕΫτϧC͸AxBʹͳΔ •ϕΫτϧ A:(Ax, Ay, Az) ͱ B:(Bx, By, Bz) ͷ֎ੵΛ C:(Cx, Cy, Cz) ͱ͢Δͱ Cx = AyBz - AzBy Cy = AzBx - AxBz Cz = AxBy - AyBx ͳʹ΍Βਆൿతɾɾɾʂɹɹɹɹɹɹɹɹɹɹɹ
  22. COPYRIGHT 2016 @ UNITY TECHNOLOGIES JAPAN COPYRIGHT 2016 @ UNITY

    TECHNOLOGIES JAPAN ֎ੵAxB ʢ AͱBͷ໘ʹਨ௚ɺ௕͕͞ฏߦ࢛ลܗͷ໘ੵʣ B A AxB |A||B|sinθ θ
  23. COPYRIGHT 2016 @ UNITY TECHNOLOGIES JAPAN COPYRIGHT 2016 @ UNITY

    TECHNOLOGIES JAPAN ݱࡏͷ޲͖͕Aͩͱͯ͠ɺBͷํ޲ʹ޲͚͍ͨͱ͖ͷτϧΫ͸ʁ B A
  24. COPYRIGHT 2016 @ UNITY TECHNOLOGIES JAPAN COPYRIGHT 2016 @ UNITY

    TECHNOLOGIES JAPAN τϧΫ͸ճస࣠ɺͭ·Γ֎ੵͷํ޲ʂ B A
  25. COPYRIGHT 2016 @ UNITY TECHNOLOGIES JAPAN COPYRIGHT 2016 @ UNITY

    TECHNOLOGIES JAPAN ΄Μͷগ͔͕ࠩ͠͠ͳ͍ͱ͖͸τϧΫΛখ͍ͨ͘͞͠ B A
  26. COPYRIGHT 2016 @ UNITY TECHNOLOGIES JAPAN COPYRIGHT 2016 @ UNITY

    TECHNOLOGIES JAPAN ֎ੵͦͷ·Μ·ͰɺΘΓͱόωͬΆ͘ͳΔʂ A AxB |A||B|sinθ B
  27. COPYRIGHT 2016 @ UNITY TECHNOLOGIES JAPAN COPYRIGHT 2016 @ UNITY

    TECHNOLOGIES JAPAN ֎ੵͦͷ·Μ·ͰɺΘΓͱόωͬΆ͘ͳΔʂ A AxB |A||B|sinθ B 90°Ҏ্Ͱ΋όω͕ऑ͘ͳΔͷͰ஫ҙ
 ʢAtan Λར༻͢ΔͳͲͰճආՄೳʣ
  28. COPYRIGHT 2016 @ UNITY TECHNOLOGIES JAPAN COPYRIGHT 2016 @ UNITY

    TECHNOLOGIES JAPAN ऴ୺଎౓ v’ ΛಘΔͨΊͷ֎ྗʢ࠶ܝʣ m:࣭ྔ k:υϥοά F0:֎ྗ v’:ऴ୺଎౓