ãUnityãå¤åããå°å½¢ã§ããããããè½ã¡ãªãããã«ç§»åãããæã£åãæ©ãæ¹æ³
å¦çã®Unityããã¸ã§ã¯ãã§ããè¦ãã®ããä¸»äººå ¬ãã£ã©ã¯ã¿ã¼ãå£ããè½ä¸ããããå£ã貫éãã¦ç§»åãããããå æ¯ã§ãã
ããã¯ããããã£ãã²ã¼ã ããªãå ãè§ãRPGã®ç§»åãã¼ãã®ãããªããã£ã©ã¯ã¿ã¼ã移åããããäºãç®çã®å ´åã¯åºæ¥ãã°é¿ãã¦æ¬²ããæã§ãã
ä»åã¯ãã£ã©ã¯ã¿ã¼ããæ³å®ããã¹ãã¼ã¸ä¸ãããè½ä¸ããªãããã«åããæã£åãæ©ãæ¹æ³ãç´¹ä»ãã¾ãã
- æå³ããªãå ´æãæ©ããªããã£ã©ã¯ã¿ã¼
- è½ä¸ãããã£ã©ã¯ã¿ã¼ã移åãããã®ã¯NavMeshã楽
- Unity 5.6ããåçãªNavMeshæ§ç¯ãå¯è½ã«
- ã¸ã£ã³ãã»è½ä¸ã¯ç¹æ®ã¢ã¯ã·ã§ã³æ±ã
- 追å æ å ±
æå³ããªãå ´æãæ©ããªããã£ã©ã¯ã¿ã¼
RPGã®ãããªã²ã¼ã ã«ããã¦ããã£ã©ã¯ã¿ã¼ãæ³å®å¤ã®ä½ç½®ã«ç§»åãããã¨ã¯å¥½ã¾ãããªãã§ããä¾ãã°éä¸ã«ãã¹ãå± ã¦ãç¡è¦ãã¦é²ããããããã²ã¼ã ã¯èããã§ããï¼æè¿ã½ã¬ãæå³çã«åºæ¥ãã²ã¼ã å¤ãå°è±¡ã§ã¯ããã¾ããï¼
ã¾ãä½ããªã空éãæ©ãããã®ãå°ãç©ãªã®ã§ãåºæ¬çã«å°é¢ã®ä¸ãæ©ããã¨ãæã¾ããã§ãã
è½ä¸ãããã£ã©ã¯ã¿ã¼ã移åãããã®ã¯NavMeshã楽
ãã¦ãå°é¢å¤å®ã¯Physicsç³»ã®å½ä»¤ã§Colliderã¨ã®è·é¢ãããã¯æ¥å°å¤å®ãè¡ãã®ã楽ã§ããããã£ã©ã¯ã¿ã¼ãã¸ã£ã³ãããªãã®ã§ããã°NavMeshãè¨å®ãã¦ãã¾ãã®ã楽ã§ãã
NavMeshãè¨å®ãNavMeshAgentã§ç§»åããã¦ããå ´åãagent.updatePositionãfalseã«è¨å®ããªãéããNavMeshã§æå®ããç¯å²ããæãåºããã¨ã¯åºæ¥ã¾ããããã£ã©ã¯ã¿ã¼ã«æå®ã®ç¯å²ç§»åãããã«ã¯ä¾¿å©ãªæ©è½ã§ãã
ä»ã®ã¢ã¤ãã£ã¢ã¨ãã¦ã¯ã足å ã«SphereCastãè½ã¨ãâ¦ããå£ãColliderã§å²ãï¼å²ã¿æããã¨ã½ã³ããè½ä¸ããï¼çãèãããã¾ãã
ãã£ã©ã¯ã¿ã¼ã¯NavMeshAgent.Moveã§åãã
ããã§ã®ãã£ã©ã¯ã¿ã¼ã¯åºæ¬çã«NavMeshAgent.Moveã§ç§»åãã¾ããä¾ãã°ã³ã¼ãã¯ãããªæãã§ãã
GetAxisã§ç§»åãæã£ã¦ãã¦Agentã«æ¸¡ãã ãã®ç°¡åãªãä»äºã§ãã
ãªãããã®è¨å®ã§ã¯NavMeshAgentã«è¨å®ããã¦ã移åç¨ãã©ã¡ã¼ã¿ã¯ã»ã¼ä½¿ãã¾ãããSpeedãAngular SpeedãAccelerationã0ã§è¯ãã§ãã
ã¤ãã§ã«ã¯Obstacle Avoidanceããã0ãNoneã§è¯ãã§ããä½ããã£ã©ã¯ã¿ã¼ã¯ç´æ¥åããã®ã§ã
ã¡ãªã¿ã«NavMeshAgentå士ãæ¥è§¦ããéãã©ã¡ããã§ãObstacle AvoidanceãLow以ä¸ãã£ã¦ãããã¦ããªããæ¥è§¦ãã¦ãã£ã©ã¯ã¿ã¼ãéãªãã®ãåé¿ãã¦ããã¾ãï¼è¦ããã«æ¼ãåºãã¾ãï¼
NavMeshããã¤ã¯ãã
ãã®ææ³ã¯NavmeshAgentã ãã§ã¯ä¸ååã§ãå¿ ãNavMeshã§ç§»åç¯å²ãå®ç¾©ãã¦ããå¿ è¦ãããã¾ãã
NavMeshAgentã移åããã«ã¯NavMeshãäºåã«ãã¤ã¯ããå¿ è¦ãããã¾ãã
NavMeshããã¤ã¯ããã«ã¯Navigation Staticã«ãã§ãã¯ãå ¥ã£ã¦ããäºã大åæã§ããã¤Navigationã¦ã£ã³ãã¦ã§ã·ã¼ã³æ¯ã«ãã¤ã¯ãã¦ããäºãå¿ è¦ã§ãã
è¦ããã«ãéä¸ã§å¤åãããããªã¹ãã¼ã¸ã«ã¯ä½¿ãã«ããã£ãæãããã¾ãããããªãNavMeshã¨ã°ã©ãã£ãã¯ã¯å¥ã«ãã¦ãNavMeshObstacleã§ç©´ã空ããçãªäºãããå¿ è¦ãããã¾ããã
Unity 5.6ããåçãªNavMeshæ§ç¯ãå¯è½ã«
å®éã以åã¯NavMeshã¯éçãªç©ã§ãããUnity 5.6ããåçã«NavMeshãæ§ç¯ãå¯è½ã«ãªã£ãã®ã§ãããã使ç¨ãã¦ãå°å½¢ãå¤åããã¹ãã¼ã¸ãã§ããããããè½ã¡ãªããããã«ç§»åããã®ãããæã£åãæ©ããå®ç¾ãã¦ã¿ã¾ãã
Â
ã¾ãã¯Navigationã®ã¦ã£ã³ãã¦ã«ãããªã³ã¯ã移åãã¦ãNavmeshã®HLAPIãå ¥æã»å°å ¥ãã¾ããDLãããã¡ã¤ã«ã®ãã¼ã¸ã§ã³ã¯ãã¨ããããææ°ãªãå¤åè¯ãããã§ãã
LocalNavMeshBuilderã§ãã£ã©ã¯ã¿ã¼ã®å¨è¾ºã®NavMeshãçæ
NavMeshãåçã«ä½ãHLAPIã¯å¹¾ã¤ãããã¾ãããä»åã¯ããã£ã©ã¯ã¿ã¼ã®å¨è¾ºã ãNavMeshãä½ããLocalNavMeshBuilderã使ã£ã¦ã¿ã¾ãã
- é©å½ãªGameObjectã«LocalNavMeshBulderã追å ããTrackedã«åãããã£ã©ã¯ã¿ã¼ãæå®ãã¾ãã
- å°é¢ã«ãªããªãã¸ã§ã¯ãã«NavMeshSourceTagãè¨å®ãã¾ã
ããã§åçã«NavMeshããã£ã©ã¯ã¿ã¼ã®å¨è¾ºã«æ§ç¯ããã¦ãNavMeshAgentçµç±ã§å°é¢ã«è½ä¸ããåãããã¨ãæå¾ åºæ¥ã¾ãã
ãªããåæè¨å®80å¹³æ¹ã¡ã¼ãã«ã¨ããªã£ã¦ã¾ãããä»åã®ç¨éã ã¨ãã£ã©ã¯ã¿ã¼ã5å¹³æ¹ã¡ã¼ãã«ãããã§ãååã§ãã
大ãããªãã¨ãã«ãã«æéããããã¾ãã®ã§ãåºæ¥ãéãå°ãããããæã§ããä½ããå°ããã¨NavMeshã®æ´æ°é »åº¦ãä¸ããã®ã§ããã®è¾ºãã¯èª¿æ´ãèããå¿
è¦ãããããã§ãã
Â
ä»åã¯ç§»åãããã£ã©ã¯ã¿ã¼ãä¸ä½ã®ã¿ãªã®ã§LocalNavMeshBuilderã使ç¨ãã¾ãããããããã¬ã¤ã¤ã¼å¨è¾ºä»¥å¤ã«ãNavMeshAgentã§åããã£ã©ã¯ã¿ã¼ãå± ãå ´åãNavMeshSurfaceã§æå®ç¯å²ã®NavMeshãæ§ç¯ããæ¹ãå®ãããããã¾ããã
ã¸ã£ã³ãã»è½ä¸ã¯ç¹æ®ã¢ã¯ã·ã§ã³æ±ã
ãã®ææ³ã§åé¡ã«ãªãã®ã¯ã¸ã£ã³ããè½ä¸çã®æ±ãã§ããåºæ¬çã«NavMeshä¸ãåãåãã®ã§ãããããå¤ããã¸ã£ã³ãã»èªç±è½ä¸çã¯åºæ¥ã¾ãããã¤ãã§ã«è¨ãã°ãOffMeshLinkã使ãã¾ããã
ãããã£ãç©ã¯ããã®ææ³ã§ã¯ãæå®å ´æã®ç¹å¥ãªã¢ã¯ã·ã§ã³ãã®ãããªå½¢ã§æ±ãã¾ãã
ã¤ã¡ã¼ã¸ã¨ãã¦ã¯ã³ã¬ãè¿ãã¦ã
- ãã£ã©ã¯ã¿ã¼ãæå®ç¯å²ã«å ¥ã£ããagent.updatePositionãfalse
- ãã£ã©ã¯ã¿ã¼ã®ç§»åãï¼ã¢ãã¡ã¼ã·ã§ã³ãTweenãMatchTargetã§ï¼è¡ã
- 移åå®äºå¾ãWarpã§NavMeshAgentã®ä½ç½®ã移å
- agent.updatePositionãtrueã§ç§»åãåé
ã¨ãã£ãæãã§ãã
Timelineã¨Navmeshã®çµã¿åãã pic.twitter.com/l4dISADioG
â 椿 (@tsubaki_t1) 2017å¹´4æ23æ¥
追å æ å ±
æ§ç
ç¹å¥ãªã¢ã¯ã·ã§ã³ãã«ããã·ã¼ã³ã§â¦
NavMesh以å¤ã§åãç©ã¨ã®é£æº
åç´ãªç§»åå¨ã
tsubakit1.hateblo.jpNavMeshã®äºã
ä»æ¥ã®ä¸è¨
ãã¹ããã¿ãã¬ããPCã§çµµæ¸ãã®è¶ 楽ããããã¤ã³ããã£ã»ã