we trying implement 2d sandbox game player can build own "machine".
so in code is, transform new object right next block shall attached , add fixedjoint2d (respectiveley wheeljoint2d) fix it. @ point noticed though, more complex machine (with many parts) can become unstable, when force applied it.
a record of bug in slow motion: https://www.youtube.com/watch?v=ym4lsuqmnfe
the angularvelocity of every part of machine starts become unstable @ point, before "explosion" in video happens. @ second 9 , 24 every object of machine , every object got in contact (strangley kinematic objects) @ center of world (right behind red block) @ 0,0.
does know might cause this? when tell best practices trace such issues.
edit: simplified version of code. how our update() method looks like:
if (input.getmousebuttondown(1) && ...) { connectselectedblock(); }
while connectselectedblock()
looks simplified this:
connectselectedblock(){ gameobject newblock = instantiate(blocktoplace); ... fixedjoint2d joint = gameobject.addcomponent<fixedjoint2d>(); joint.connectedbody = newblock.getcomponent<rigidbody2d>(); joint.autoconfigureconnectedanchor = false; return joint; }
one of expensive , time consuming activity in unity balance physics objects using joints (and like). video shows typical behavior result of imbalanced physics interaction. quite find have put script on each "key" object can change joint parameters @ runtime. not easy task, can guarantee that. also, make sure physics related logic happens in fixedupdate() method, avoiding in update() operation might have physics interaction of sort.
Comments
Post a Comment