Hello Guest

Author Topic: can tilemap and sprite support navmesh navigation of unity3d ?  (Read 8987 times)

miloveme

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 2
    • View Profile
I tried to make navigation map of unity3d on generated sprite from tiledmap or sprite of 2d toolkit. but it didn't work.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: can tilemap and sprite support navmesh navigation of unity3d ?
« Reply #1 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.

miloveme

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: can tilemap and sprite support navmesh navigation of unity3d ?
« Reply #2 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)

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: can tilemap and sprite support navmesh navigation of unity3d ?
« Reply #3 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;
}
}
}