c# - GameObjects vibrate when in contact with terrain. -


first rather know why happening fix. knowing allow me learn while cut , paste code won't. (an alternative fix nice , thank baffles me , want know why).

set up: have primitive shape go (gameobject) spawn above terrain. go has rigid body , attach script it. seed.cs class inherits several functions class called body. once spawned go falls , comes contact terrain , problems happen. go can either go through terrain, stuck half inside, falls stuck , thrown out of ground, or if fall slow enough continuously vibrate.

i have tried changing collision detection 3 different types prior running scene on go had little affect. found did work while scene running change collision detection 1 option , problem seems disappear. can throw change in start function of body class , works fine. actual options collision detection irrelevant fixing problem requires change it. continuous discrete or discrete continuousdynamic fact change makes problem go away.

i'm hoping has idea why is. scale go if helps.

the code might spaghetti recreational programming , first time ever using unity.

bellow code. simulationcontroller

public class simulationcontroler : monobehaviour {      public gameobject entities;      // use initialization     void start () {         entities = gameobject.find ("enteties");          entityhandler entityhandler = entities.getcomponent<entityhandler>();         int id = entityhandler.createnewentity ();          gameobject adam = entityhandler.getentetity (id);         entity adamentity = adam.getcomponent<entity>();         adamentity.storeresources (1000, 1000);          gameobject go = (gameobject)instantiate(resources.load("body shapes/cube", typeof(gameobject)), new vector3(9, 6, 20), quaternion.euler(43, 30, 0));         go.name = "apple tree";         go.rigidbody.angulardrag = 2;         go.rigidbody.drag = 2;         go.rigidbody.mass = 444;         go.addcomponent<seed> ();         seed goseed = go.getcomponent<seed> ();         goseed.setdna("33493339411953125429875244");         goseed.setentityid (id);         goseed.growth();         goseed.growth();         goseed.growth();         goseed.growth();      }      // update called once per frame     void update () {      } }   public class seed : body { }  using unityengine; using system; using system.collections; using system.collections.generic;  public class body : monobehaviour {      private int timet = 0;      public int maxtimet = 5;     public string dna;     public int dnaposition = 0;     public bool growing = true;     public int entityid;      // use initialization     void start () {         this.rigidbody.collisiondetectionmode  = collisiondetectionmode.continuousdynamic;     }      public void setentityid (int id)     {         entityid = id;     }      public void setdna(string sdna)     {         this.dna = sdna;     }      int dnareader(int size){          string tempstring = "";         (long = 0; < size; i++)         {             //debug.log(dna.length);             if(dna.length>dnaposition)             {                 tempstring = tempstring + this.dna[dnaposition];                 dnaposition += 1;             }         }         if (tempstring == "")          {             tempstring = "-1";         }         debug.log (tempstring);         return int32.parse(tempstring);      }       public void growth()     {          gameobject entities = gameobject.find ("enteties");;         entityhandler entityhandler = entities.getcomponent<entityhandler> ();         gameobject goentity = entityhandler.getentetity (entityid);         entity entity = goentity.getcomponent<entity>();          int growth;         vector3 scale;         int dnacode = 0;         bool found = false;         while (!found)          {             int code = dnareader (3);             switch (code) {             case 111:                 //debug.log ("go back");                 dnaposition -= dnareader (2);                 if(dnaposition<0)                 {                     dnaposition = 0;                 }                 found = true;                 break;              case 222:                 //debug.log ("go forward");                 dnaposition += dnareader (2);                 if(dnaposition>this.dna.length)                 {                     this.growing = false;                 }                 found = true;                 break;              case 331:                 growth = dnareader(1);                 bool temp = entity.requestresources(growth*2,growth);                 if(entity.requestresources(growth*2,growth))                 {                     this.rigidbody.mass += growth;                     scale = this.transform.localscale;                     scale.x += growth;                     this.transform.localscale = scale;                 }                  found = true;                 break;              case 332:                 growth = dnareader(1);                 if(entity.requestresources(growth*2,growth))                 {                     this.rigidbody.mass += growth;                     scale = this.transform.localscale;                     scale.y += growth;                     this.transform.localscale = scale;                 }                  found = true;                 break;              case 333:                 growth = dnareader(1);                 if(entity.requestresources(growth*2,growth))                 {                     this.rigidbody.mass += growth;                     scale = this.transform.localscale;                     scale.z += growth;                     this.transform.localscale = scale;                 }                  found = true;                 break;              case 334:                 int growthx = dnareader(1);                 int growthy = dnareader(1);                 int growthz = dnareader(1);                  growth = growthz*growthy*growthx;                 this.rigidbody.mass += growth;                  if(entity.requestresources(growth*2,growth))                 {                      scale = transform.localscale;                       scale.x += growthx;                      scale.y += growthy;                      scale.z += growthz;                       transform.localscale = scale;                 }                  found = true;                 break;               case 335:                 scale = this.transform.localscale;                  growth = dnareader(1);                 scale.x = growth;                  scale.y = growth;                  scale.z = growth;                  this.transform.localscale = scale;                  found = true;                 break;              case 411:                 //create body part                 int shape = dnareader(1);                 int type = dnareader(1);                  int px = dnareader(1);                 int py = dnareader(1);                 int pz = dnareader(1);                  int rx = dnareader(1);                 int ry = dnareader(1);                 int rz = dnareader(1);                  int bf = dnareader(1);                 int bt = dnareader(1);                 break;              case -1:                 this.growing = false;                 found = true;                 break;             }         }     } } 

have tried checking collider of object make sure fitting in object entirely.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -