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

3865d333f9dc02cd417575c2cfa1606f?s=47 unitydojo
November 05, 2016
2.1k

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

3865d333f9dc02cd417575c2cfa1606f?s=128

unitydojo

November 05, 2016
Tweet

Transcript

  1. ूதߨ࠲ͦͷ3
 ϓϩ͕ڭ͑Δ୤ॳ৺ऀεΫϦϓτज़ʂ ϢχςΟɾςΫϊϩδʔζɾδϟύϯ ϑΟʔϧυɾΤϯδχΞ ҆ݪ ༞ೋ

  2. ෺ཧΛ࢖ͬͨ ूதߨ࠲ͦͷ3
 ϓϩ͕ڭ͑Δ୤ॳ৺ऀεΫϦϓτज़ʂ ϢχςΟɾςΫϊϩδʔζɾδϟύϯ ϑΟʔϧυɾΤϯδχΞ ҆ݪ ༞ೋ

  3. COPYRIGHT 2016 @ UNITY TECHNOLOGIES JAPAN COPYRIGHT 2016 @ UNITY

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

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

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

    TECHNOLOGIES JAPAN ຊ೔ͷ͓͸ͳ͠ •ʮ͋ͱͰ΍ͬͯΈΑ͏ʂʯ •ͱࢥͬͯ΋Β͑ΔΑ͏ʹ͕Μ͹Γ·͢ʂ
  7. None
  8. None
  9. COPYRIGHT 2016 @ UNITY TECHNOLOGIES JAPAN ࣮ԋύʔτ ·ͣ͸γϯϓϧʹ ΩϟϥΫλʔΛ ಈ͔ͯ͠ΈΑ͏

  10. COPYRIGHT 2016 @ UNITY TECHNOLOGIES JAPAN ࣮ԋύʔτ COPYRIGHT 2016 @

    UNITY TECHNOLOGIES JAPAN
  11. COPYRIGHT 2016 @ UNITY TECHNOLOGIES JAPAN ࣮ԋύʔτ COPYRIGHT 2016 @

    UNITY TECHNOLOGIES JAPAN
  12. COPYRIGHT 2016 @ UNITY TECHNOLOGIES JAPAN ࣮ԋύʔτ COPYRIGHT 2016 @

    UNITY TECHNOLOGIES JAPAN
  13. COPYRIGHT 2016 @ UNITY TECHNOLOGIES JAPAN ࣮ԋύʔτ COPYRIGHT 2016 @

    UNITY TECHNOLOGIES JAPAN
  14. COPYRIGHT 2016 @ UNITY TECHNOLOGIES JAPAN ࣮ԋύʔτ InputManager ͰೖྗΛγϯϓϧ ʹ͓ͯ͜͠͏

  15. COPYRIGHT 2016 @ UNITY TECHNOLOGIES JAPAN ࣮ԋύʔτ COPYRIGHT 2016 @

    UNITY TECHNOLOGIES JAPAN
  16. COPYRIGHT 2016 @ UNITY TECHNOLOGIES JAPAN Time.deltaTime Λ࢖͓͏

  17. COPYRIGHT 2016 @ UNITY TECHNOLOGIES JAPAN Δtʹ͍ͭͯ෮श

  18. COPYRIGHT 2016 @ UNITY TECHNOLOGIES JAPAN COPYRIGHT 2016 @ UNITY

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

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

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

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

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

    TECHNOLOGIES JAPAN Δtͱ͸ ͭ·ΓɺΔt͸ඵؒϑϨʔϜ਺ͷٯ਺ Δt 1ඵ 20ϑϨʔϜ
  24. COPYRIGHT 2016 @ UNITY TECHNOLOGIES JAPAN ࣮ԋύʔτ Δt ΛϓϩάϥϜʹ૊Έࠐ΋͏

  25. COPYRIGHT 2016 @ UNITY TECHNOLOGIES JAPAN ࣮ԋύʔτ FixedUpdate Λ࢖͓͏

  26. COPYRIGHT 2016 @ UNITY TECHNOLOGIES JAPAN ࣮ԋύʔτ COPYRIGHT 2016 @

    UNITY TECHNOLOGIES JAPAN
  27. COPYRIGHT 2016 @ UNITY TECHNOLOGIES JAPAN ʲ֮ॻʳ Update ͸̍ඵؒʹԿճݺ͹ΕΔ͔Θ͔Βͳ͍ʢੑೳ͕௿͍؀ڥͩͱ গͳ͘ͳΔʣ

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

  29. COPYRIGHT 2016 @ UNITY TECHNOLOGIES JAPAN ࣮ԋύʔτ COPYRIGHT 2016 @

    UNITY TECHNOLOGIES JAPAN
  30. COPYRIGHT 2016 @ UNITY TECHNOLOGIES JAPAN ࣮ԋύʔτ COPYRIGHT 2016 @

    UNITY TECHNOLOGIES JAPAN
  31. COPYRIGHT 2016 @ UNITY TECHNOLOGIES JAPAN ࣮ԋύʔτ AddForce ʹೖྗ஋Λ ͦͷ··ೖΕΔ

  32. COPYRIGHT 2016 @ UNITY TECHNOLOGIES JAPAN ࣮ԋύʔτ COPYRIGHT 2016 @

    UNITY TECHNOLOGIES JAPAN
  33. COPYRIGHT 2016 @ UNITY TECHNOLOGIES JAPAN ࣮ԋύʔτ Drag Λ࢖ͬͯ෺ମΛࢭΊΑ͏

  34. COPYRIGHT 2016 @ UNITY TECHNOLOGIES JAPAN ࣮ԋύʔτ COPYRIGHT 2016 @

    UNITY TECHNOLOGIES JAPAN
  35. COPYRIGHT 2016 @ UNITY TECHNOLOGIES JAPAN Drag Λ੍͢Δ΋ͷ͸ Rigidbody Λ੍͢Δ

  36. COPYRIGHT 2016 @ UNITY TECHNOLOGIES JAPAN COPYRIGHT 2016 @ UNITY

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

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

    TECHNOLOGIES JAPAN ऴ୺଎౓Λࢉग़͢Δهࣄ͕͋Γ·ͨ͠ʂ
  39. COPYRIGHT 2016 @ UNITY TECHNOLOGIES JAPAN http://qiita.com/yuji_yasuhara/ items/1f438f0f27f5ef854a73

  40. COPYRIGHT 2016 @ UNITY TECHNOLOGIES JAPAN COPYRIGHT 2016 @ UNITY

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

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

  43. COPYRIGHT 2016 @ UNITY TECHNOLOGIES JAPAN v t

  44. COPYRIGHT 2016 @ UNITY TECHNOLOGIES JAPAN όωΛѻ͓͏

  45. COPYRIGHT 2016 @ UNITY TECHNOLOGIES JAPAN COPYRIGHT 2016 @ UNITY

    TECHNOLOGIES JAPAN όωͱ͸ɺڑ཭ʹൺྫ͢Δྗͷ͜ͱ ऑ͍ ڧ͍
  46. 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); }
  47. COPYRIGHT 2016 @ UNITY TECHNOLOGIES JAPAN COPYRIGHT 2016 @ UNITY

    TECHNOLOGIES JAPAN Φʔόʔγϡʔτʢ໨ඪϙΠϯτΛ௨Γա͗Δʣ x t
  48. COPYRIGHT 2016 @ UNITY TECHNOLOGIES JAPAN Φʔόʔγϡʔτ͠ͳ͍όω܎਺ Λ஌Γͨ͘ͳΔ

  49. COPYRIGHT 2016 @ UNITY TECHNOLOGIES JAPAN COPYRIGHT 2016 @ UNITY

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

  51. COPYRIGHT 2016 @ UNITY TECHNOLOGIES JAPAN ճసΛ࢖͓͏

  52. COPYRIGHT 2016 @ UNITY TECHNOLOGIES JAPAN AddTorque Λཧղ͠Α͏

  53. COPYRIGHT 2016 @ UNITY TECHNOLOGIES JAPAN τϧΫ͸෺ମΛճసͤ͞Δྗ

  54. COPYRIGHT 2016 @ UNITY TECHNOLOGIES JAPAN AddForce ͸Ґஔ AddTorque ͸ճస

  55. COPYRIGHT 2016 @ UNITY TECHNOLOGIES JAPAN τϧΫ͸ ճస࣠ͱେ͖͞Ͱද͢

  56. COPYRIGHT 2016 @ UNITY TECHNOLOGIES JAPAN AddTorque(new Vector3(2, 0, 0))

    ͸ X࣠ʹରͯ͠2ͷτϧΫ
  57. COPYRIGHT 2016 @ UNITY TECHNOLOGIES JAPAN τϧΫͷ͍͢͝ͱ͜Ζ ॏͶͯʢ଍ͯ͠ʣ΋େৎ෉ʂ

  58. COPYRIGHT 2016 @ UNITY TECHNOLOGIES JAPAN ࣮ԋύʔτ ඈߦػͷૢ࡞Λ࡞ͬͯΈΑ͏

  59. COPYRIGHT 2016 @ UNITY TECHNOLOGIES JAPAN

  60. COPYRIGHT 2016 @ UNITY TECHNOLOGIES JAPAN ࣮ԋύʔτ Input.GetAxis Ͱ AddTorque

  61. COPYRIGHT 2016 @ UNITY TECHNOLOGIES JAPAN

  62. COPYRIGHT 2016 @ UNITY TECHNOLOGIES JAPAN Ϥʔ(yaw) ϐον(pitch) ϩʔϧ(roll)

  63. COPYRIGHT 2016 @ UNITY TECHNOLOGIES JAPAN ϩʔϧͯ͠͠·͏໰୊

  64. COPYRIGHT 2016 @ UNITY TECHNOLOGIES JAPAN ֎ੵΛ࢖͓͏

  65. 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 ͳʹ΍Βਆൿతɾɾɾʂɹɹɹɹɹɹɹɹɹɹɹ
  66. COPYRIGHT 2016 @ UNITY TECHNOLOGIES JAPAN COPYRIGHT 2016 @ UNITY

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

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

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

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

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

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

  73. COPYRIGHT 2016 @ UNITY TECHNOLOGIES JAPAN

  74. COPYRIGHT 2016 @ UNITY TECHNOLOGIES JAPAN ࣮ԋύʔτ COPYRIGHT 2016 @

    UNITY TECHNOLOGIES JAPAN
  75. COPYRIGHT 2016 @ UNITY TECHNOLOGIES JAPAN ࣮ԋύʔτ COPYRIGHT 2016 @

    UNITY TECHNOLOGIES JAPAN
  76. COPYRIGHT 2016 @ UNITY TECHNOLOGIES JAPAN ࣮ԋύʔτ ศརؔ਺
 AddRelativeTorque

  77. COPYRIGHT 2016 @ UNITY TECHNOLOGIES JAPAN ࣮ԋύʔτ COPYRIGHT 2016 @

    UNITY TECHNOLOGIES JAPAN
  78. COPYRIGHT 2016 @ UNITY TECHNOLOGIES JAPAN ࣮ԋύʔτ ඈߦػͳͷͰ Ϥʔ͸ϩʔϧ͠ͳ͕Β

  79. COPYRIGHT 2016 @ UNITY TECHNOLOGIES JAPAN ࣮ԋύʔτ COPYRIGHT 2016 @

    UNITY TECHNOLOGIES JAPAN
  80. COPYRIGHT 2016 @ UNITY TECHNOLOGIES JAPAN લਐʂ

  81. COPYRIGHT 2016 @ UNITY TECHNOLOGIES JAPAN COPYRIGHT 2016 @ UNITY

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

  83. COPYRIGHT 2016 @ UNITY TECHNOLOGIES JAPAN

  84. COPYRIGHT 2016 @ UNITY TECHNOLOGIES JAPAN ͓͠·͍ ͜ͷߨԋͷUnityϓϩδΣΫτ͸ͪ͜Β͔Βμ΢ϯϩʔυͰ͖·͢ɿ https://www.dropbox.com/s/3aokgqnqs05sdyg/UnityDojoSpecial2016Yasuhara.zip?dl=0