Posts: 16
Threads: 6
Joined: Dec 2013
Hi again Jake,
I'm trying to make a dynamic Mesh Collider for my mesh having the "SplinePathMeshBuilder" script.
Something like :
Code:
GetComponent(MeshCollider).sharedMesh = null;
var mesh : Mesh = GetComponent(MeshFilter).mesh;
GetComponent(MeshCollider).sharedMesh = mesh;
And... it works but then I can't Edit the shape anymore with the curvySpline Script.
Is there any build in code in order to do that properly ?
I didn't find anything in the doc.
Thanks a lot !
Seb
Posts: 690
Threads: 71
Joined: Jan 2015
Did you tried to use the sharedMesh from the MeshFilter? Besides that, what exactly means you can't edit it any more?
Posts: 16
Threads: 6
Joined: Dec 2013
Thank you for your quick answer
Yes, I tried to use the sharedMesh from the MeshFilter.
Well, when I "re-build" the collider of my "spline mesh" with the code above, then his script "SplinePathMeshBuilder" stops to work.
That"s to say, if I edit any of its value : Shape Radius, UV mode... or if I change the position of a Control Point it has no effect at all. There is something broken.
Posts: 690
Threads: 71
Joined: Jan 2015
01-02-2014, 08:32 AM
(This post was last modified: 07-01-2014, 06:52 PM by Jake.)
Hm,
I just checked with the MeshBuilder example. I added a MeshCollider to the RoadPath GameObject and additionally this script (MeshColUpdate.cs):
Code:
using UnityEngine;
using System.Collections;
public class MeshColUpdate : MonoBehaviour {
MeshFilter mFilter;
MeshCollider mCol;
// Use this for initialization
void Start () {
mFilter = GetComponent<MeshFilter> ();
mCol = GetComponent<MeshCollider> ();
}
// Update is called once per frame
void Update () {
mCol.sharedMesh = null;
mCol.sharedMesh = mFilter.mesh;
}
}
Of course that's horrible slow, but the Collider updates properly when I change Extrusion parameters or modify the underlying spline. Can you test the above script with the example scene, just to be sure this behaves the same on your side?
Jake
Posts: 16
Threads: 6
Joined: Dec 2013
Amaziiiiing !!!!! Jake !
Just perfect ! thank you so much for your script, it was exactly what I was looking for
Seb
Posts: 7
Threads: 2
Joined: Jun 2014
Hi,
I am trying to use this script as it seems like a solution to my issues as well. However whenever I copy and paste the script in My scene gives me this error:
Assets/TestScript.cs(10,53): error CS1525: Unexpected symbol `)'
I do not code so Im not sure exactly how to fix it, I have tried to delete the symbol it finds unexpected but that just causes other issues.
I am using Playmaker to create my game but I was hoping to find a way of getting this script to create a collider for me.
Any help would be much apreciated.
Cheers
Jasper.
Posts: 690
Threads: 71
Joined: Jan 2015
The wysiwyg editor of the forum scrambled my initial input. I just updated the code, it should work now. It's pretty easy to create a custom action out of it, I'll hopefully get the time to do this tommorow.
Jake
Posts: 7
Threads: 2
Joined: Jun 2014
Great thanks a bunch for that!
One thing of note is that when you use a mesh collider on the object that is collinding with this roadpath it falls right through still, so you need to use primative colliders to get it to work. But thats not too much of an issue for me.
Cheers Jake.
Posts: 690
Threads: 71
Joined: Jan 2015
Just a note that updating any existing mesh collider is now part of v1.61.