Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by Questionaire · Aug 01, 2011 at 06:32 AM · meshcolliderwheelcolliderfrictionmesh-deformation

Wheelcollider has zero friction on run-time created mesh

I'm creating a mesh at run-time by adding new vertices etc. to it and I want a vehicle to drive on it. Problem is that the vehicle simply slides of with no friction at all! And its only with the wheelcolliders, other colliders work fine (have friction). For instance if I flip the vehicle on its roof it has friction as intended. And its also only for the run-time created mesh. The wheelcolliders work fine on terrain / other collider / other static mesh.

This is the code used to create the mesh. leftSpawner and rightSpawner are simply two objects that move around to specify the coordinates for new mesh vertices. As for the wheelcolliders no setting I change makes any difference (default doesn't work either) - but it's only for the created mesh, else they work fine.

EDIT: I want to point out that the code below isn't the main focus here. Has anyone got wheelcolliders to work on a runtime created mesh at all?? The code is only posted in case anyone spots something weird with it. But if anyone has wheelcolliders working in any way on a runtime created mesh please let me know!

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 
 public class SpawnGroundMesh : MonoBehaviour 
 {
     public float spawnInterval;
     
     private const int maxVertices = 512;
 
     private List<Vector3> newVertices;
     private List<int> newTriangles;
     private List<Vector2> newUV;
     private List<Vector4> newTangents;
     
     private Mesh newMesh;
     private GameObject leftSpawner;    
     private GameObject rightSpawner;
     
     
     // Use this for initialization
     void Start ()
     {
         newMesh = GetComponent<MeshFilter>().mesh;
         leftSpawner = GameObject.FindWithTag("LeftPos");
         rightSpawner = GameObject.FindWithTag("RightPos");
         
         newVertices = new List<Vector3>(maxVertices);
         newVertices.Add(leftSpawner.transform.position);
         newVertices.Add(rightSpawner.transform.position);
         
         newTriangles = new List<int>((maxVertices - 2) * 3);
         
         newUV = new List<Vector2>(maxVertices);
         newUV.Add(new Vector2(leftSpawner.transform.position.x
         ,     leftSpawner.transform.position.z));
         newUV.Add(new Vector2(rightSpawner.transform.position.x
         , rightSpawner.transform.position.z));
         
         newTangents = new List<Vector4>(maxVertices);
         Vector3 newTangent = newVertices[newVertices.Count-1]
          - newVertices[newVertices.Count-2];
         newTangents.Add(new Vector4(newTangent.x, newTangent.y, newTangent.z, 0));
         newTangents.Add(new Vector4(newTangent.x, newTangent.y, newTangent.z, 0));
         
         SpawnNewPoints();
 
     }
     
     // Update is called once per frame
     void Update () 
     {
     }
     
     void FixedUpdate()
     {
         if(Vector3.Distance(rightSpawner.transform.position
         , newVertices[newVertices.Count-3]) > spawnInterval)
         {
             SpawnNewPoints();
         }
         
         UpdateAtatchedPoints();
         
         newMesh.Clear();
         newMesh.vertices = newVertices.ToArray();
         newMesh.uv = newUV.ToArray();
         newMesh.triangles = newTriangles.ToArray();
         newMesh.RecalculateNormals();
         newMesh.tangents = newTangents.ToArray();
         GetComponent<MeshFilter>().mesh = newMesh;
         
         GetComponent<MeshCollider>().sharedMesh = null;
         GetComponent<MeshCollider>().sharedMesh = newMesh;
 
     }
     
     private void UpdateAtatchedPoints()
     {
         newVertices[newVertices.Count-2] = leftSpawner.transform.position;
         newVertices[newVertices.Count-1] = rightSpawner.transform.position;
     }
     
     private void SpawnNewPoints()
     {
         //make space if full
         if(newVertices.Count >= maxVertices)
         {
             RemoveOldPoints();
             
             //add vertices
             newVertices.Add(leftSpawner.transform.position);
             newVertices.Add(rightSpawner.transform.position);
         }
         else
         {
             //add vertices
             newVertices.Add(leftSpawner.transform.position);
             newVertices.Add(rightSpawner.transform.position);
         
             //add triangle list
             newTriangles.Add(newVertices.Count - 4);
             newTriangles.Add(newVertices.Count - 2);
             newTriangles.Add(newVertices.Count - 1);
 
             newTriangles.Add(newVertices.Count - 4);
             newTriangles.Add(newVertices.Count - 1);
             newTriangles.Add(newVertices.Count - 3);
         }
         
         //add uv coords
         newUV.Add(new Vector2(leftSpawner.transform.position.x
         ,     leftSpawner.transform.position.z));
         newUV.Add(new Vector2(rightSpawner.transform.position.x
         , rightSpawner.transform.position.z));
         
         //add tangents
         Vector3 newTangent = newVertices[newVertices.Count-1]
          - newVertices[newVertices.Count-2];
         newTangents.Add(new Vector4(newTangent.x, newTangent.y, newTangent.z, 0));
         newTangents.Add(new Vector4(newTangent.x, newTangent.y, newTangent.z, 0));
         
     }
     
     private void RemoveOldPoints()
     {
         newVertices.RemoveRange(0, 2);
         newUV.RemoveRange(0, 2);
         newTangents.RemoveRange(0, 2);
     }
     
 }
Comment
Add comment · Show 4
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Rmaniac · Aug 02, 2011 at 06:33 PM 0
Share

If you format the code with the 101010 button you'll have better luck getting someone to read through this one :)

avatar image Meltdown · Aug 02, 2011 at 06:43 PM 0
Share

$$anonymous$$y eyes... they burn... 1010101 pleaseeeeee....

avatar image Questionaire · Aug 03, 2011 at 06:51 PM 0
Share

Huh? It already is!

Just to make sure I turned 1010101 off/on again and asked a friend to view it. Looks fine to him. Is it fixed now?

avatar image Rmaniac · Aug 03, 2011 at 09:22 PM 0
Share

Yeah, it's good now - yesterday, not so much :)

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Wheel has no friction on mesh collider of another GameObject. 0 Answers

Wheelcolliders falling through ground 1 Answer

I am making a racing game and I cant figure out how to calculate the angular velocity for my custom wheel collider 0 Answers

About physic calculation of wheelcollider 1 Answer

Ray cast not hitting the backside of mesh collider attached to a spherical mesh object 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges