During the development of Mechropolis, our level designer came to me requesting the ability to limit the area in which the Stationary Thrower robot could turn to keep it’s arms from clipping into walls and to give the level designer more control when creating challenges.
The robot in the image above is the Stationary Thrower. It turns toward the player and throws her into the air when she steps onto it’s plate, kind of like a robotic jump pad.
Limiting the angles allowed for the robot was not a problem, but smoothly turning toward it’s target angle while avoiding the restricted segment proved to be a bit more of a challenge than I had anticipated. I had previously used Unity’s built in
Quaternion.RotateTowards function for this, but that function always does the shortest rotation possible which would cause the robot to rotate through obstacles if that was the shortest route.
I decided to approach the problem by manually rotating the robot towards it target on a plane with support for my own angular limits. I’ve tried keeping things as general as possible and while my use for this is limited to the xz-plane, this approach should work on any plane. (more…)