Object Viewing and Body Rotation

Christiane Snyder

If you look down in the game, you’ll be able to view the body of the giant robot, but it won’t turn with you. We can fix this by creating a “GiantRobotRotate” C# script and adding it to the giant robot object in the scene. In this new script, we’ll track the main camera’s rotation and continuously set the rotation of the robot’s y axis to the value from the main camera. This will ensure that the body will only spin to face horizontal points and the model’s feet will stay on the ground rather than face upwards or downwards.

Even though the reticle will highlight whatever is gazed at, the experience user will need a more obvious indicator of what will be shot at if the lasers are fired. We’ll use a moving spotlight as this indicator. Create a new script called “TargetSpotlight” and attach it to the spotlight game object in the scene. This script will also track the Main Camera’s transform, but instead of maintaining the same rotation of the camera, it will find the location of what should be highlighted in the scene with a raycast from the location of the main camera in the scene, down the camera’s forward. Whatever object is hit by this raycast is currently the focal point of the scene. The “TargetSpotlight” script will then then rotate the light so that is shines directly on the point of the scene that is should be in focus.