ãUnity3ãã³ã¤ã³ãè½ã¨ãï¼Mathf.Sin, Time.time, MovePositionãã³ã¤ã³ããã·ã£ã¼2ã
Unity5.0.0f4 Personal(2015å¹´4æ)
Â
ååã®ç¶ããæ¸ãããã¦é ãã¾ãã
Â
ä»åã¯é ç½®ããããã·ã£ã¼ãåããã¦ãã³ã¤ã³ãè½ã¨ãã¨ããã¾ã§é²ãããã¨æãã¾ãã
Â
ããã·ã£ã¼ï¼èµ¤æ ï¼ãåãã
Â
Â
ãç®æ¨ãããã·ã£ã¼ãåãããã³ã¤ã³ãç»é¢ä¸ã¸è½ã¨ãï¼
Â
ã¾ãã¯Pusherã«éåã®å½±é¿ãä¸ãããããRigidBodyã³ã³ãã¼ãã³ãã追å ãã¾ãã
Â
Inspectorã®AddComponentããPhysics>RigidBodyã¨é²ãã¨ããã¾ãã
Â
RigidBodyã³ã³ãã¼ãã³ã追å å®äº
Â
éåã追å ãã¾ãããä»åã¯å®ä½ç½®ã§ã®ã²ã¼ã ã§ãã®ã§ãéåã«å¾ã£ã¦ä¸ã¸è½ã¡ã¦ããã£ã¦ã¯å°ãã¾ããããã§ãä¸ç»åã®UseGravityã®ãã§ãã¯ãå¤ãã¦ä¸ããããããããã¨ã§ãPusherãå®ä½ç½®ã«ä¿ã¤ãã¨ãã§ãã¾ãã
Â
ã¾ããIs Kinematicã®ãã§ãã¯ãå ¥ãã¦ããã¦ä¸ããã
Â
IsKinematicã«ãã§ãã¯ãå ¥ã£ã¦ããªãã¨ãä¾ãã°ããã·ã£ã¼ãã³ã¤ã³ã«è§¦ããæãããã·ã£ã¼ã«ãååããã¦ãã¾ããä½ç½®æ å ±ãããã¦ãã¾ãã®ã§ãã
Â
IsKinematicã«ãã§ãã¯ãå ¥ã£ã¦ããã°ãããã·ã£ã¼ã¯ã³ã¤ã³ã«ã¶ã¤ãã£ã¦ããåãä½ç½®ã§ç¹°ãè¿ãåãã¦ãããããã«ãªãã¾ãã
Â
éåãç¡å¹ã«ãããããRigidBodyã³ã³ãã¼ãã³ãã追å ããæå³ãªããããªããï¼ï¼ï¼ã¨æãããããããã¾ããããããããRigidBodyã¯ã©ã¹ã®MovePositionã¡ã½ããã使ãããã«å¿ è¦ãªã®ã§ããã²ã¨ã¾ãã½ã¼ã¹ã確èªãã¦ã¿ã¾ãããï¼
Â
Â
MovePosition(Vector3)ã使ãã¨ãæå®ããæ¹åã¸ãªãã¸ã§ã¯ãã移åããããã¨ãã§ãã¾ããMovePositionã®è¯ãã¨ããã¯ãä»ã®ãªãã¸ã§ã¯ãã®åå¨ãå¤å®ããªãã移åãããããªãã¸ã§ã¯ãã¨ãªãã¸ã§ã¯ããéãªã£ããããªãç¹ã§ãã
Â
ã¡ãªã¿ã«åããããªå¦çã«Transform.Translate(Vector3)ã¨ããå¦çãããã¾ããããã¡ãã¯æå®ããæ¹åã«ã¯ã¼ãããã¤ã¡ã¼ã¸ã§ããããããªãã¸ã§ã¯ãã¨ãªãã¸ã§ã¯ããéãªã£ã¦ãã¾ããã¨ãããã®ã§æ³¨æã§ãã
Â
MovePositionã使ãåã«ãGetComponent<RigidBody>().ãã¨ããè¨è¿°ããã¦RigidBodyã¯ã©ã¹ã使ããç¶æ ã«ãã¦ããã¾ãããã®è¨è¿°ã¯Unity4ã¨Unity5ã¨ã§éãã®ã§ããã詳ããã¯ä»¥åã®è¨äºã«æ¸ããã¦ããã¾ãã®ã§ããåç §ä¸ãããÂ
Â
 ãGetComponent<Rigidbody>.ãã®è¨è¿°ã¯ããããã©ããªãã¸ã§ã¯ãã«Rigidbodyã³ã³ãã¼ãã³ããåãä»ãããã¦ããªãå ´åã¨ã©ã¼ã¨ãªã£ã¦ãã¾ãã¾ãããã®ãããUseGravityã®ãã§ãã¯ãå¤ããRigidbodyã³ã³ãã¼ãã³ããPusherã«åãä»ããã¨ããããã§ãã
Â
Rigidbodyãä»ãã¦ãªãã¨ãããªã¨ã©ã¼ãåºã¦ãã¾ã
Â
ããã§ã¯ã½ã¼ã¹ã®è§£èª¬ã«æ»ãã¾ããFixedUpdateã®ä¸ã§Mathf.Sin(Time.time)* 0.5fã¨ããè¨è¿°ãããã¾ãããMathf.Sinã¯-1ãã1ã®éã§å¾å¾©çã«å¤ãå¤åãããé¢æ°ã§ããããã«0.5ãããã¦ããã®ã§ã-0.5ãã0.5ã®éã§å¾å¾©çã«å¤ãå¤åããã¦ããã¾ãã
Â
Time.timeã¯ã²ã¼ã èµ·åããã®çµéæéã表ãã¦ããã¾ãã1ç§åä½ã®å¦çãè¡ãæã«ä½¿ãã¾ãã
Â
ã¾ã¨ããã¨ãAwakeã§Pusherã®åæposition(X:0, Y:0.4, Z:0.7)ãåå¾ãã¦ãã²ã¼ã å ã§1ç§â2ç§â3ç§â4ç§â5ç§ãããã¨æéãé²ãã¨ãPusherã®Z軸ã0 â 0.5 â 0 â -0.5 â0 ãããã¨ããå¤åããªãããã«ç¹°ãè¿ããã³ã¤ã³ãã¼ã¶ã¼ã®ããã·ã£ã¼ã®åããå®ç¾ãã¦ããã¨ããããã§ãã
Â
ã課é¡ï¼ãã³ã¤ã³ãéç£åããããã·ã£ã¼ã®åãã確èª
ããã§ã¯ååä½æãã¦ãããCoinã®Prefabã§ã³ã¤ã³ãæ´ã«éç£åãããã¨æãã¾ãã
Â
éç£åãä½ç½®ãã¾ã°ãã«
Â
ãã¾ã£ãï¼Coinã«Rigidbodyãä»ãå¿ããã¾ã¾éç£åãã¦ãã¾ãã¾ãããï¼ãå®å¿ä¸ãããPrefabãããªãã¸ã§ã¯ããè¤è£½ããå ´åãã³ãã¼å ã®Prefabã®è¨å®ãå¤ããã°ã³ãã¼å ã®ãªãã¸ã§ã¯ãã®è¨å®ã¯å ¨ã¦é£åãã¦å¤ããã¾ãã
Â
ã³ãã¼å ã«Rigidbodyãã¤ããã ãã§ã³ãã¼ããå ¨ã¦ã®ã³ã¤ã³ã«åæ
Â
ã¾ããåã®å ´åãªã®ã§ãããã³ã¤ã³ã«ä»ãã¦ããColliderãSphereColliderã§ãã£ãã®ã§ãããåé¤ã
Â
å³ã¯ãªãã¯ããRemoveComponentã§åé¤
Â
代ããã«MeshColliderãåãä»ãã¦ä¸ãããæ´ã«ãUnity5ããMeshColliderã使ãå ´åã¯Convixã«ãã§ãã¯ãå ¥ããªããã°ãªããªããããªã®ã§ããã®ããã«ãã¾ãã
Â
Convixã«ãã§ãã¯
Â
ã³ã¤ã³ã
Â
è½ã¡ã¦
Â
ããã·ã£ã¼ã«æ¼ããã¾ã
Â
ããã§ããã·ã£ã¼ã«æ¼ããã¦ã³ã¤ã³ãè½ã¡ãããã«ãªãã¾ããã
ã²ã¨ã¾ãä»åã¯ããã¾ã§ã§ãããããã¨ããããã¾ããã
Â
ãUnityéçº3ãä¸æºåãã³ã¤ã³ããã·ã£ã¼1/6ã