Fishery : Steering in 3D
February 9, 2017
Creating fluid steering controls has been difficult, but I had a breakthrough yesterday. In order to get really smooth loops (horizontal and vertical and everything in between), I realized that I had to abandon the way I had implemented steering thus far. The old, simple approach was to simply use the steering controls to orient the avatar and having swim button apply a force to the avatar’s Rigidbody on every FixedUpdate() tick. It works fine, but I don’t like the feel of it. It’s like driving a sluggish submarine, where change of directions feel sluggish due to the drifting created by the Rigidbody’s momentum. This also made looping really clunky too, where the avatar wouldn’t been swimming in a circular path (more like a wobbly elliptical path). While these controls and physics might be more realistic, I don’t think it’s fun or intuitive.
And so, I changed the steering pad to manipulate a dynamic rotation point and corresponding rotation axis. Every turn the avatar makes is now potentially a fluid orbit around that rotation point. Instead of applying a force to the rigidbody, I now simply calculate the distance delta that the avatar would have swum in a straight line over the last Time.deltaTime and then either apply as a RigidBody.MovePosition() along a straight line if there’s no steering, or along the circumference of a potential orbit.
Now changing direction feels snappy, especially 180 degree turns. There’s still a problem with losing up-vector orientation during complex turns and loops. I’ll explain what I mean and what I did to solve it next time.
Henry Ho