Use a tracking camera

Source: Internet
Author: User

Now that you are ready to fly, let's make some changes to the small game in the past and look at its appearance.

The resetgame method creates a paper airplane object and stores it in a variable called the _ plane class to facilitate future access. After the camera is created, no tracking object is found after initialization. Therefore, the camera position is subject to the switch provided manually rather than following the plane.

After the project is running, the Initialization Configuration appears. Houses and planes are visible, but cameras are slowly centered around the scene. The cameraobject. Update function of the game uses a simple rotation and conversion matrix to process the camera's moving path.

When the player tapped the screen, however, we activated the tracking camera. In the update method of the game class, check the pat on the screen. Each time it is detected, it adds four camera configurations for the next time. BelowCodeDescribes how to activate the tracking camera.

 
// Follow the plane from behindCamera. chaseobject = _ plane; camera. chasedistance = 1; camera. chaseelevation = 0.3f;

In fact, all required settings will be set to the camera in this way. The only change requires our cameraobject. Update function: If it detects that the chase camera is in the active State (the camera's chaseobject is not equal to null), it simply calls the base class and then returns. Further conversion of any camera code will interfere with or completely replace the camera's own perspective setting conversion.

Once you run the project and tap the screen, you will see the perfect effect of the chase camera. After the project is run in this mode ,.

After the second pat on the screen, the camera will return to the front of the plane and look back. This is implemented simply by setting the camera's chasedistance to a negative value (-1 in this case ). Remember that although an airplane knows its flight path and can calculate its coordinates in the future, the camera does not know its future coordinates, but it is still in front of it. It is important to be able to set coordinates without future information. If the object is controlled by a player, it will not be able to predict the future movement.

The last mode is activated on the third Pat screen. It displays the first person called the camera and is activated by setting the chasedistance to 0. This is a small change we have to make in order to make it better: Put the camera directly in the flight location, resulting in rendering of the Cutting Image of the first half of the flight, this looks strange-for first-person cameras, we simply don't want to render the flight.

To solve this first-person rendering problem, we made a small change in the paperplaneobject. Draw method. If it detects that it is the camera's chaseobject and the camera's chasedistance is 0, it does not plot and returns.

For fun, we can add some other flying objects to the scene.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.