Unity3d loads the fbx model for simple direction control

Source: Internet
Author: User

It may be easy to start learning U3D and record some learning things. Do not spray.

In the terrain, I placed a model of a truck and used the arrow keys to control the movement of the truck. The camera follows the movement of the truck.

I will not record the basic operations.

1. First, create a terrain map, add a terrain map, brush a bit of grass, and then plant a Vertex Tree. OK. A simple terrain is formed.

2. How are trucks controlled?

First, create a cube. It is very easy to control a cube. Add a write control script for this cube.

VaR movespeed = 5;

VaR rotatespeed = 20;

Function Update (){

If (input. getkey (keycode. W )){

This. Transform. Translate (vector3.forward * time. deltatime * movespeed );

} Else if (input. getkey (keycode. s )){

This. Transform. Translate (vector3.forward * time. deltatime *-movespeed );

} Else if (input. getkey (keycode. )){

This. Transform. Rotate (vector3.up * time. deltatime *-rotatespeed );

} Else if (input. getkey (keycode. d )){

This. Transform. Rotate (vector3.up * time. deltatime * rotatespeed );

}

}

The code is very simple, that is, to move the cube through the keyboard.

Now a cube can be moved. How can we move a truck?

Set the position of the cube to (0, 0), and set the position of the truck to (0, 0, 0 ).

Note that the zaxis direction of the cube and truck should be the same. Scale the Cube as big as the truck, and then remove the mesh Renderer of the cube. In this way, the cube appearance will not be rendered. Move the truck to the cube in the hierarchy panel.

In this way, the cube is moved.

Finally, do not forget to set camera to follow the cube.

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.