c# - Unity physics - how to make objects bob down then up as if in space with gravity? -


alright, getting physics here in unity , ive been through unity's forums well, cant figure out how create specific gravity related effect -

i have these rigid bodies of mass 100 able push off platform (my game bunch of platforms set in space) open space. because checked affected gravity, fall.

what need objects slide off platform, fall little bit bob , stay there floating. if pushed off in space, cant keep going. bob down, up, stay , float.

this seems lot more complicated thought, ive played gravity , high values fall straight down (not out, obviously) , low values float above when pushed off. there doesn't seem sweet spot neither go down or up, bob.

how can achieve this? masses 100.

my suggestion implement force function tries resemble arkimedes' principle. key potential dependant on how far down object is: further down water object is, more lift force. such, key function here (and tricky one) volumebeneathsurface.

double liftforce(object) {     const double waterlevel = 0.0;     const double density = 1000.0; // kg/m^3 -- using water atm      double vol = volumebeneathsurface(object, waterlevel);      double displacedmass = vol*density; // density = m/vol     double displacedweight = displacedmass*gravity; // f = m*a     return displacedweight; } 

now, tricky part here can calculate amount of volume beneath water surface. imagine tricky geometry might rotated -- can become complicated want. simplest case approximate shape non-rotating box.

double volumebeneathsurface(object, double surfacelevel) {      // assuming object has `height`, `width`, , `depth`      // assuming coordinate references center of object      double r = object.y - surfacelevel - object.height/2.0; // how of object beneath surface      if (r > 0)          return 0.0; // object purely above      else if (r < object.height)          return object.height*object.width*object.depth; // whole object beneath      else          return abs(r)*object.width*object.depth; // partly under } 

realistic things in water bobs , down little, motion fades away. due energy transferring object , creating waves in water. have no such effect here, our object bob , down forever. add friction object , motion should fade out.


Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -