Dynamic Stability

First, thanks to all that have helped me this far.

I have a Flying controller script, and I would like to add dynamic stability ie, when the player is not pressing a key, the player object returns to flat and level. Everything else is good so far, but without this, it’s a nightmare and impossible to control.

I am halfway through the second scripting tutorial so I can get things to rotate and I even understand what’s happening in the script I have ( a huge accomplishment for me), but I am at a loss on how this would work. I can imagine that it would involve a translate command with a deltaTime to control roll rate (?), but how would the controller know what flat and level actually is? It would have to get an absolute position value from the world, not the player posistion, yes? How would that work and still maintian forward or backward velocity?

Maybe I’m too old to learn this stuff… :wink:

Any thoughts? Thanks again.

18932–616–$flycontrolledscript1_844.js (6.8 KB)

Well, my first thought is that I have no idea what the key-reading routines are doing. :wink: It seems to me that it would be simpler and more flexible just to use a few lines of Input.GetAxis() code, no? As for the stabilizing, I’d probably see if there’s no user input, and if that’s the case, then rotate the x and z axes back to zero a little bit each frame. Set pitch and roll to zero too. Flat and level would be Vector3(0, x, 0)…the x meaning whatever, since that’s the direction the player is facing. That doesn’t affect velocity at all; no translating involved either.

–Eric

I haven’t looked at your sample, but I was working on the same thing yesterday and came up with something that was really easy to accomplish. Basically I created “If” statements to check if the object is not level and then used small amount of torque force to turn it until it became level. The concept is super easy. Here’s the thread I posted: http://forum.unity3d.com/viewtopic.php?t=2782 which is hopefully enough to get you going.