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
  Wheel Collider to propel along Spline Phunyun 1 21 08-23-2019, 10:09 PM
Last Post: _Aka_
  Move the Create Mesh of a CurvyGenerator Out of the Main Parent UsernameHed 3 214 07-08-2019, 06:57 PM
Last Post: _Aka_
  Trying to create a moving train that slows and stops at stations Novian 7 2,708 09-13-2018, 08:46 PM
Last Post: ClaudePorter
  Curvy to create splines from 3D models Sergei543071 1 1,066 08-07-2018, 02:34 PM
Last Post: _Aka_

Forum Jump: