ãUnity2ããããã¯ãæ¶ããï¼AddForce, OnCollisionEnter, Physics Materialããããã¯å´©ã2ã
Unityãã¼ã¸ã§ã³ï¼5.0.0f4 Personal (2015å¹´4æ)
Â
ååã®ç¶ããæ¸ãã¦ããããã¨æãã¾ãã
ä»åã¯ããã¼ã«ã«åããå ããã®ã¨ããã¼ã«ããããã¯ã«å½ãã£ãæã«ãããã¯ãæ¶ãããã¨æãã¾ãã
ãç®æ¨ããã¼ã«ãã¶ã¤ãã¦ããããã¯ãæ¶ãï¼
ã課é¡ï¼ããã¼ã«ãåãã
ã¾ãã¯ååä½æãããã¼ã«ã«ãRigidBodyã³ã³ãã¼ãã³ãããã£ã¤ãã¦ä¸ããã
ããã¦ãRigidBody>Constraintsãéãã¦ãFreezePositionã®ZãFreezeRotationã®X,Y,Zã«ãã§ãã¯ãå ¥ãã¦ä¸ããããããããã¨ã«ãã£ã¦ããã¼ã«ã¯Z軸æ¹åï¼ã¤ã¾ãç»é¢ã®å¥¥ï¼ã¸ã¯é²ã¿ã¾ããããå転ãå ¨ãããããªããªãã¾ãã
次ã«ç©ºæ°æµæã表ãDragã0ãUseGravityã®ãã§ãã¯ãå¤ãã¦ç¡éåç¶æ ã«ãã¦ä¸ããã
質éã表ãMassã¯1ã«ãã¦ã1000ã«ãã¦ãç¡éåãªã®ã§å¤ãããªãã§ããå転ã®ç©ºæ°æµæã表ãAngularDragããå転ãå¶éãã¦ããããå¤ãå¤ãã¦ãåé¡ãªãã§ãã
æå¾ã«CollisionDetectionãContinuousã«å¤æ´ãã¾ããããããããã¨é£ç¶çã«è¡çªå¤å®ããã¦ããã¾ããä»åã®ãã¼ã«ã¯çµæ§æ©ãåãã®ã§ãDiscreteï¼åå¥å¤å®ï¼ã®ã¾ã¾ã ã¨ããæãã¦ãã¾ãã¾ãã
ãããªæãã«è¨å®ãã¾ãã
Â
ãã¦ç¶ãã¦ãBallãªãã¸ã§ã¯ãã«ä»¥ä¸ã®C#scriptãä»ãã¾ãã
AddForceã使ã£ã¦ããã¼ã«ã«å³ä¸ã¸ã®åãå ãã¦ãã¾ãã
ãâ»â»â»Unity5ã«ãããã«ã¼ã«å¤æ´â»â»â»ã
AddForceã®ãããªéåé¢ä¿ã®å¦çãè¡ãæãRigidBodyã¨ããã³ã³ãã¼ãã³ããå¿ è¦ã¨ãã¾ãããUnity4ã¾ã§ã¯ãrigidBodyï¼é æåãå°æåï¼ãã¨æ¸ãã°ä½¿ããã¨ãã§ãã¾ãããããã¯Unityãæé»çã«ãGetComponent<RigidBody>()ãã¨ããå¦çããã£ã¦ããã¦ããã®ã§ãããUnity5ããã¯æ示çã«æ¸ããªãã¨ãããªããªãã¾ããã
ä¸ã®ã³ã¼ãã®ããã«Startã¡ã½ããã§ä¸åº¦GetComponentããrbãã«å ¥ãã¦ããã°ããã¨ã¯ãã®scriptå ã§ãrbãã¨æ¸ãã ãã§ä½åº¦ã§ã使ãåããã¨ãã§ãã¾ããï¼ããããã£ãã·ã¥ããã¨è¨ãã¾ããï¼
Â
AddForceã®ä¸çªå¾ãã«ã¤ãã¦ããForceMode.VelocityChangeã¯ããããã¯å´©ãã®æã¯æ±ºã¾ãæå¥ã ã¨ãããã¨ã§ããããã®è³ªéãç¡è¦ãã¦ãrigidBodyã«ç¬æã«é度å¤åã追å ãã¾ãããã ããã§ãã
ããã§ã¨ãããããã¼ã«ãåãããã«ãªãã¾ããã
Â
ã課é¡ï¼ããããã¯ã¨ã®è¡çªå¤å®
ãã¼ã«ããããã¯ã«å½ãã£ãæããã¼ã«ãæ¶ããããã«ãããã¨æãã¾ãã
é常ã«ã·ã³ãã«ãªscriptããããã¯ã«ä»ãããã¨ã§ããã¼ã«ã¨ãããã¯ãè¡çªããæã«ãããã¯ãæ¶ããã¨ãã§ãã¾ãï¼
ãããã¯ã«å½ã£ã¦ãè·³ãè¿ããã¨ãªãã触ããç©å ¨ã¦ãæ¶ãå»ãæªéã®ãããªãã¼ã«ãå®æãã¾ãã
è·³ãè¿ããªãã»ã»ã»
ããã§ã¯ã²ã¼ã ã¨ãã¦ãã¾ãé¢ç½ããªãã®ã§ããããã¯ã«ã¶ã¤ãã£ãæãã¼ã«ãè·³ãè¿ãããã«ãã¾ãããï¼
Project>Create>Physics Materialãé¸æãããbounceãã¨ååãã¤ãã¦ä¿åãã¦ããã¾ãããã
Inspectorããè¨å®ãã¦ããã¾ãã
DynamicFrictionã¯ç§»åä¸ã®æ©æ¦ã«ããæ¸éãå®ç¾©ãã¾ãã0ã«è¨å®ãã¦åãç¶ããããã«ãã¾ãããï¼
StaticFrictionã¯ä½ãã«æ¥ãã¦ããæã®æ©æ¦ãå®ç¾©ãã¾ãã0ã«è¨å®ãã¦ç¶ºéºã«åå°ããããã«ãã¾ããããï¼æ°·ã®ä¸ããã¹ãã¢ã¯ã·ã§ã³ãä½ãéã«ããStaticFrictionã0ã«ããã¨ãããã§ããããï¼
è·³ãè¿ã度åããå®ç¾©ããBouncinessã¯1ã«ãã¾ãããããããã¨ã«ãã£ã¦åã失ããè·³ãè¿ã£ã¦ããã¾ãã
FrictionCombineã¯ãï¼ã¤ã®è¡çªãããªãã¸ã§ã¯ãã®æ©æ¦ãå®ç¾©ãã¾ããAverageã¯æ©æ¦ãå¹³ååãããMinimumã§ï¼ã¤ã®ãã¡å°ããæ¹ã®æ©æ¦å¤ã使ãããMaximumã¯éã«å¤§ããå¤ã使ãããMultyplyã¯ï¼ã¤ã®æ©æ¦å¤ãä¹ç®ããã¾ããä»åã¯Minimumã«è¨å®ãã¾ãã
BounceCombineã¯ãFrictionCombineã®æ©æ¦å¤ãè·³ãè¿ã度åãã«å¤ãã£ããã®ã§ãããã¡ãã¯Maximumã«è¨å®ãã¾ãã
PhysicsMaterialããã¼ã«ã«ã¤ãã¾ããSphereColliderã³ã³ãã¼ãã³ãã®Materialã«ã¤ããã¨ã»ã»ã»
Â
ãããã¯ãæ¶ãããã¼ã«ããã£ããã¨è·³ãè¿ã£ã¦ããã¾ãï¼
Â
ä»åã¯ããã¾ã§ã次åã¯ãã¬ã¤ã¤ã¼ãåããã¦ãã²ã¼ã ãç¶ãããã«ãããã¨æãã¾ãã
ãããã¨ããããã¾ããã
Â