Unity first person controller usage

Introduction: This section mainly introduces the use of the official FPS package to achieve first-person control. Since the official case is very complete, there is no need to repeat the wheel, so this article does not contain any code implementation~


Asset Store Get Pack

As we all know, don’t make the models or scripts you can find in the resource store; the
official asset store of Unity contains a lot of free models and game scenes built by the masters. If you need to practice, you can search more;

Click to go directly to the resource store to get the FPS package

insert image description here
After entering the above link and opening the webpage, please log in first, and then click "Add to My Resources", which may need to be clicked twice (I only officially added it to the unity package manager after the second click)

After the prompt box of successful addition pops up at the top of the webpage, close the webpage and open unity



Unity imports the first-person controller package

Select window->package manager to open the package manager.
insert image description here
Select asset in the package drop-down box in the upper left corner of the pop-up window, which means to obtain the resource list we purchased (for nothing) from the resource store; wait for the
network request to obtain the list, and enter in the search box on the right The name of the first-person controller package;
insert image description here
there are two buttons in the lower right corner of the above picture because I have already downloaded it. If you are downloading for the first time, there should be a download button in the lower right corner; after downloading,
click import to import the package.

It is recommended to import all the content in the package directly, because you cannot be sure whether the content you choose not to import has a dependency relationship with the resources you will use. In order to avoid dependency loss errors, you should decide as much as possible before canceling the import of some unnecessary content



Unity deploys first-person controller

After importing the package, we go directly to the resource manager's asset -> starterassets -> firstpersoncontroller -> prefabs and
we will see four prefabs;
insert image description here
drag all three except the prefab in the upper right corner to the scene;

We found that in addition to the capsule character itself, there are two camera-related components;
as shown in the figure, the upper one is the main camera, and the lower one is the virtual camera;
insert image description here
due to the related content of the plug-in cinemachine, it is too complicated , I won’t introduce too much here. Let’s click on the PlayerFollowCamera component and find the follow thing in the property panel on the right;
we need to assign it to the sub-object PlayerCameraRoot in the player capsule
insert image description here
. After setting, we will find the main camera And the virtual camera all ran to the player's head and fixed it. When we entered the game, we found that we could operate the character normally.
insert image description here


some notes

  1. Neither the main camera nor the virtual camera needs to exist as subcomponents of the Player! Once we set the follow property, it will be automatically bound to the player!
  2. Once the main camera is bound, it cannot be moved. We can only adjust the position of the camera by moving the PlayerCameraRoot component.

END will introduce the development and optimization of related first-person shooter games in the future. I hope everyone can support it QWQ

Guess you like

Origin blog.csdn.net/delete_you/article/details/126768446