I’m getting ready to start my first project in Unity. For this project, I need to simulate a vehicle underwater. Is there a way to adjust “gravity”? From the script reference and the docs it looks like gravity is either -off- or -on-. Is there a way to simulate a gravity that is either less or more than 9.8 m/sec(2)?
I wonder if you really do need to change gravity, wouldn’t this be more drag then any thing else? I suppose maybe to get it to “feel right” it might need less gravity. Just a thought.
You can change gravity to whatever you want; just go to Edit->Project Settings->Physics, and enter a number for any of the 3 axes. You can script that too.
Although gravity is still the same underwater…you might instead look at simulating buoyancy using spring joints. For example, just to give a really rough idea: make a cube, make it a rigidbody, give it a mass of 30, 50 drag, 10 angular drag, use gravity. Then give it a spring joint, with 30 spring, 200 damper, 1 min distance, 50 max distance. Get a side view and zoom out quite a bit, hit play, and then drag the cube down and let go. Up we go.
Of course, the cube will get dragged to its originating point on all axes, not just Y. To fix that, make an empty, give it a rigidbody (not using gravity), and attach the spring joint of the cube to the empty. Then you’d move the empty some distance above the surface, and use scripting to move the empty around so it always has the same X and Z coordinates as the cube. Substitute an underwater vehicle for the cube, play with the settings to get the buoyancy right, and there you go…theoretically… At least that way you can have sinking objects and floating objects at the same time.
On the other hand, it’s tough to make controllable objects that are also rigidbodies. You might just want to script all of the movement for anything the player is controlling; it’d be simple to give any object a constant upward force if that’s what you wanted.
Thanks for all the ideas and tips. I hadn’t considered using springs to simulate the neutral buoyant effects, but am thinking that my particular project may be a bit too complex for that method.
What makes this a bit more complicated is that this underwater vehicle is tethered to another vehicle via a long cable “umbilical cord”. I’ll need to configure the vehicle so it can be maneuvered, but only within the confines of the umbilical cord. I figure I’ll model the connecting cord with a series of connected cylinder sections, using joints or hinges between the sections.
I haven’t created a physics model this complex before and this will be my first project with Unity, so it should be pretty challenging and educational…
Ok, I just some experimenting. I played around with the gravity settings in the sample project “Add Force.unity” and I’m getting some weird behavior. What I’m trying to acheive is where my object (the cube in this project) is very nearly neutrally buoyant (almost zero gravity) but will slowly decend. When I adjust the Y gravity value to -0.8 it’s close to what I want, but as soon as I change the value to anything greater than that (ie. -0.7) it appears that gravity no longer functions. After I apply a brief force to the box, it just holds it’s position. Any idea why? Is this a limitation of Unity or is there something in the script I missed?
Based on my experiments, I’m guessing a gravity setting of about -0.2 to -0.4 is where I’ll want to set it, but those don’t seem to work.
Thanks!
EDIT: Never mind, figured it out. Found the “sleep” value that turns off physics, when I lower this it behaves as it should. Cool…
Thanks Morgan, I’ve studied that a bit already as well as the demo that has the “dragon”. Looks like I’ll have a fair bit of latitude to simulate the stiffness/flexibility and buoyancy of the connecting cable.
Another thing that further complicates this is that the moveable vehicle has two articulating arms. Not sure if I’ll simulate this with physics (joints and forces) or canned animations. It’ll be a fun simulator, the user(s) will need to use 3 joysticks to control it (1 analog joystick plus a gamepad with 2 analog joysticks).
I’m just doing my homework at the moment while I finish my last project. Can’t wait to start digging into Unity, looks like it will be fun.