So controls were crappy with all the button mash. Asked my local consultant and he suggested the usual mouse + wasd controls. So had to come up with a way to make ship face towards the mouse pointer while still using the physics system. Done a version where the facing is "forced" by simply rotating the object, but because it isn't by applying force to the attached "rigidbody", it caused all sorts of bugs when the ship bumped into other objects.
That's why I ended up learning about PID controllers, and that is why I am talking about them now.
So what does the current controller do?
It takes the angle between where the ship is facing, and the vector that points from the ship towards the mouse and tries to "drive" it to 0 by applying torque to the ship. It also takes how fast the ship is spinning and tries to "drive" that to 0 by applying torque.So the ship turns towards the mouse, and gradually slows down and stops when it faces it.
I borrowed the algorithm from another script that was written for 3d objects, then watched some videos on PID controllers and it was a piece of cake.
Going to be extremely useful when I start building and using other scripts to enable the enemies whoop your ass. :)
Thanks Nathan for the sprites and the tips. I am looking forward to bug you more.
Hopefully soon I get to blow people up with my awesome enemy AI's. /probably also borrowed, or bought on unity asset store/
Post a Comment