|
Post by wyliam on Jan 31, 2015 4:18:15 GMT
I'm looking to get an accurate mesh collider for the resulting chunks. I'm not using the hex restricted movement, and am simply moving across the landscape similar to an RTS. However when I apply the mesh collider post world generation to the final chunks, the result is still flat. Aaron's A* scan doesn't pick it up and thus my units move through mountains, et al.
Any suggestions on how to get an accurate collision? I see the references for getting the world points and height applied to the actors that come with the project. Unfortunately, I was hoping to take advantage of the pathfinding and avoid traversing over obstacles they shouldn't (i.e. mountains, etc.).
Thoughts on the best way to go about achieving this?
|
|
|
Post by tango209 on Jan 31, 2015 15:53:54 GMT
It appears a collision mesh isn't created. Probably due to this being hex based and using A* for pathfinding. Though I think I read somewhere there was talk of maybe needing it for line of sight tests.
The framework is setting everything to 'walkable' in HexGraph's ScanInternal. I believe you would need to inherit and override or modify that to determine which hexes you would want not walkable.
|
|
|
Post by khash on Jan 31, 2015 16:25:12 GMT
HexGraph have: public override void ScanInternal(OnScanStatus statusCallback) and there is line which adds node and makes is walkable: pn.Walkable = true; you may want to make it conditional and/or not add those nodes at all. If you need terrain Mesh you may produce it in the same way as it is done for non dx11 mode : Chunk: static public Mesh ProduceTerrainMesh(Chunk source) set resolution of it to some reasonably small value and use it for collision tests. you may still use dx11 flat terrain (tessellated terrain) for visual display to get crispy quality and use this lower resolution mesh for collision tests Cheers
|
|
|
Post by wyliam on Jan 31, 2015 21:58:46 GMT
Awesome! Using the non-dx11 chunk mesh worked like a charm! I simply created a collision mesh in the "CreateGameObjectWithTextures()" method in Chunk.cs and set it up for use before A* scanned the scene. Now I just need to get in there and reduce the resolution to keep it thrifty.
Thanks!
GameObject chunkCollision = GameObject.Instantiate(worldOwner.chunkBase) as GameObject;
MeshFilter m = chunkCollision.GetComponent<MeshFilter>();
if (m.sharedMesh != null) { GameObject.Destroy(m.sharedMesh); }
m.sharedMesh = ProduceTerrainMesh(this);
chunkCollision.transform.parent = chunkObject.transform;
chunkCollision.name = "collision_" + position;
// ensure the collider is pointing to the new mesh
MeshCollider col = chunkCollision.GetComponent<MeshCollider>();
col.sharedMesh = m.mesh;
// hide collision mesh MeshRenderer rend = chunkCollision.GetComponent<MeshRenderer>();
rend.enabled = false;
|
|
|
Post by khash on Feb 1, 2015 10:03:11 GMT
Cheers!
|
|