Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Create a collider ( SplinePathMeshBuilder)
#1
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
Reply
#2
Did you tried to use the sharedMesh from the MeshFilter? Besides that, what exactly means you can't edit it any more?
Reply
#3
Thank you for your quick answer Smile
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.

 
Reply
#4
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

 

 

 
Reply
#5
Amaziiiiing !!!!! Jake !

Just perfect ! thank you so much for your script, it was exactly what I was looking for Smile

Seb
Reply
#6
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.
Reply
#7
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
Reply
#8
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.
Reply
#9
Just a note that updating any existing mesh collider is now part of v1.61.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Heart Create beautiful curves ShiroeYamamoto 3 13 03-26-2024, 06:25 PM
Last Post: _Aka_
  Is it possible to create a road texture at runtime? artsung 1 4 01-30-2024, 09:30 AM
Last Post: _Aka_
  Collider doesn't get created by the CreateMesh Module pako88 5 11 12-26-2023, 11:13 AM
Last Post: _Aka_
  Combine 2 Create Mesh nodes to one single Mesh danne_lindwall 1 13 02-16-2023, 08:25 PM
Last Post: _Aka_

Forum Jump: