2D Toolkit Forum

2D Toolkit => Support => Topic started by: miloveme on June 18, 2013, 09:00:41 am

Title: can tilemap and sprite support navmesh navigation of unity3d ?
Post by: miloveme on June 18, 2013, 09:00:41 am
I tried to make navigation map of unity3d on generated sprite from tiledmap or sprite of 2d toolkit. but it didn't work.
Title: Re: can tilemap and sprite support navmesh navigation of unity3d ?
Post by: unikronsoftware on June 18, 2013, 10:40:22 am
The nav mesh system in Unity uses the render mesh to generate the navmesh. The tilemap render mesh is flat as it is built out of sprites. Sprites, by nature, are flat.
You will need to do some workarounds, to transfer the colldier mesh to a separate render mesh, and then use that to generate the navigation mesh.
Title: Re: can tilemap and sprite support navmesh navigation of unity3d ?
Post by: miloveme on June 19, 2013, 12:18:09 am
In my opinion, generated mesh by 2d toolkit and default plane mesh are same. but when I used plane, navmesh was generated.
Is it different ? If do, could you explain how to do what you mentioned as workaround (transfer collider mesh to another render mesh)
Title: Re: can tilemap and sprite support navmesh navigation of unity3d ?
Post by: unikronsoftware on June 19, 2013, 03:30:30 pm
It definitely works for me.
I mean it generates "something", i.e. the data for a plane.

Create a plane next to your tilemap, and make sure its generating on that too. Sometimes if the tilemap is too small (i.e. sprite size is too small) it will be below the threshold to create one.

Use a script like this to transfer the collider geometry into something "usable" by the navmesh system - simply delete everything named @TMP after baking. Also you should make sure that the tilemap render data is set to navigation static before baking.
p.s. the script is unsupported, but it does work.


Code: [Select]
using UnityEngine;
using UnityEditor;
using System.Collections;

public class TransferMeshToRender {

[MenuItem("TransferMesh/CollisionToRender/Do")]
static void Do() {
MeshCollider[] meshColliders = Selection.activeGameObject.GetComponentsInChildren<MeshCollider>();
foreach (MeshCollider m in meshColliders) {
GameObject go = new GameObject("@TMP");
go.transform.parent = m.transform;
go.transform.localPosition = Vector3.zero;
go.transform.localScale = Vector3.one;
go.transform.localRotation = Quaternion.identity;
MeshFilter mf = go.AddComponent<MeshFilter>();
MeshRenderer mr = go.AddComponent<MeshRenderer>();
mf.sharedMesh = m.sharedMesh;
}
}
}