[Unity3D] Unity3D game development-dynamic shadow in Unity3D

Source: Internet
Author: User

Hello everyone, I'm Qin Yuanpei. Welcome to follow my blog. My blog address is blog.csdn.net/qinyuanpei.

Today, I want to share with you the dynamic shadow in Unity3D. I have relived my favorite game "Gu jianqitan 2" and found that the game has added three free DLC versions after the update. These three DLC types are mainly used to expand the Main Line Plot. the favorite of bloggers here is the seventh day of the controllable role. From this point, we can see that candle dragon has acquiesced in a new main character group represented by Shen Ye and Xie Yi to some extent. I remember that when the previous release of "Gu jianqitan 2", the outside world commented on this game. Some people think that it is a rising star in domestic stand-alone games in recent years. Its drastic innovation has brought new vitality to the traditional domestic RPG games. Some people think that it is not uncommon in the combat mode. It lacks a sense of combat, and the story is lengthy. We will not discuss what is right or wrong with the outside world about this game. We will only discuss what is worth studying in this game. After playing the DLC, the blogger clearly felt that candle Dragon had made great efforts in the combat mode. In the seventh day of the role, the blogger liked it very much, this role moves people to feel like an ACT game. It seems that candle dragon deliberately guided the players in this direction when designing this DLC, in short, when the blogger controlled this role, he found the feeling of playing the meteor butterfly sword many years ago. Now, let's talk about our games first. If you are interested in domestic RPG games, you can talk to me. Let's take a look at the figure below:


We noticed that there was a green Halo at the foot of the protagonist's 7th day. In the game, this was because the protagonist collected the flexibility of a wooden attribute. Here we do not focus on the properties of gold, wood, water, fire, earth, and five elements. What we really want to focus on is the green halo. In the game, when a player moves, this green halo can move along with the player. This is what we want to focus on today, so how to achieve this effect in Unity3D? Let's take a look at today's content!

1. Simple texture Method

The so-called simple texture method is to directly append a shadow translucent texture to the bottom of the role and let it move along with the role. Generally, this shadow Object is a subobject of the role model, the shadow generation effect is as follows:


For details about this shadow translucent texture, refer to this article: Unity3D game production (III)-role shadow production on mobile platforms. However, this method has a serious problem, that is, this shadow can only be applied to a flat ground. If the concave area of the ground is uneven or the ground is covered by an object, it is easy to see the penetration effect. Since the blogger has read this article before, he paid special attention to this issue when playing this DLC. As a result, the blogger found that "Gu jianqitan" uses this method, because the ground in the blue is relatively flat, this method can be used to achieve this effect, but when the ground passes through the steps in the middle of the two rooms, the ground is concave and uneven, therefore, the shadow under the player's foot will be covered in part. Therefore, as a technician, we must be good at discovering problems in our daily lives.


Ii. Projection Generation Method

This method is essentially a decimal technique, that is, setting a projector and then casting the shadow to the place where you want to display the shadow, the advantage of this method is that the projection effect does not depend on the geometric shape of the projected area. That is, the projected area can have any concave and convex surfaces or handle various obstacles. The steps to implement this method are:

(1) Use GameObject-> Create Empty to Create an Empty object named "Shadow Projector ".

(2) Add the Projector Component to the empty object through Component-> Effects-> Projector, and achieve the following Effects by translating, rotating, and adjusting parameters:


(3) drag the prepared Material into the Material option to project the shadow.

We can soon find that this method also has a problem, that is, not only the shadow is generated in the scenario, but the role's body also turns black, because the Ignore Layers of the projector is set to Nothing, when we set the negligible layer as the role's layer Player, the role can no longer be projected.

The above two methods are the mainstream shadow generation methods on mobile platforms. The advantage is that the generation is simple, easy to use, and the calculation workload is small, but the disadvantage is also prominent, that is, the shadow is false, it is not a real object shadow, so it is not realistic. However, as a beginner, we should continue to grasp this basic method in a down-to-earth manner, because only when we have mastered the basics, we can try to break through ourselves and internalize our knowledge into our own things. Now let's use today's method to implement a simple example. First, create a simple scenario, as shown in:


To let us focus more on the production of dynamic shadows, we use the official character model here. To use the projector, we import the Projectors package into the project:


Next we create an empty object named Projector, and add a Projector component to it. Next we adjust the position and angle of the Projector so that it is perpendicular to the role downward projection. Create a separate layer Player for the role, set Ignore Layers of the Projector component to Player, so that the role remains unchanged, and select Shadow Material as the Material. In this case, the effect in the scenario is as follows:


We can see that the shadow effect has been displayed under the soles of the feet of our role. After confirming that the x coordinate of the Projector and role is the same as the zcoordinate, we drag it under the model to make it a subobject of the model. In this way, the shadow will be consistent with the model. Well, we will run the program:


We can see that the program runs perfectly. Please ignore the dark shadows under your role, haha.

Now let's work together to implement the shadow effect based on the Paster method. First, prepare an image. This is an image that the blogger finds himself:


Next we will add a Plane in the scenario named TextureProjector, drag the image to TextureProjector, and adjust it to the appropriate size.


Similarly, after determining that the texture and x of the role are consistent with the Z coordinate, we drag it into the bottom of the model to make it a child object of the model. Run the program:


In practical applications, smooth texture rotation may be solved. Here we only want to demonstrate how to implement shadow Based on textures. Of course, we do not recommend using Plane generated by Unity itself, because the number of faces generated by Unity is large, you can use modeling tools such as 3DMax to generate row modeling, which can optimize our projects. Well, today's content is like this. I hope everyone will like it. Haha, go to bed!


Daily proverbs: the most difficult stage in life is not that no one understands you, but that you do not understand yourself.


If you like my blog, please remember my name: Qin Yuanpei. My blog address is blog.csdn.net/qinyuanpei.
Reprinted please indicate the source, Author: Qin Yuanpei, the source of this article: http://blog.csdn.net/qinyuanpei/article/details/32355267


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.