Search Unity

Underwater Bouyancy

Discussion in 'Scripting' started by soapstar, Mar 5, 2012.

  1. soapstar

    soapstar

    Joined:
    Apr 4, 2011
    Posts:
    56
    Hi,

    I am currently building an underwater game and i am desperately trying to figure out how i could easily represent bouyancy underwater. Basically all i need is my script to keep checking whether the rigidbody it pointing upwards, if the body comes into contact with something obviously the physics will rotate the body on one or two axis, i want the body to then react to this change in rotation and rotate back to the 'level' position (pointing upwards).

    The method i am using currently checks if either the x or z rotation is greater or less than 1, if it is then a relative torque is added on that particular axis with the value of the rotation being the actual rotation value (this helps to damp the rotation). The biggest problem is the body keeps adjusting itself back and forth?

    I think there must be a much simpler way to make sure the body is pointing upwards?

    Thanks for your help! :)
     
  2. runner

    runner

    Joined:
    Jul 10, 2010
    Posts:
    865
    Last edited: Mar 5, 2012