Unity3d arpg game development the first map of the original fantasy and the improvement of the jump

Source: Internet
Author: User

We have finally implemented character animation, camera control, and day-and-night systems. Now let's continue. To facilitate the compilation of scripts such as enemies, we plan to give a rough picture of the first place today. As a result, I drew a map for a long time ..... Second (second) Second

My talents in art are terrible ..... In addition, when the map is drawn halfway, unity crashes again .... I forgot to save it ). So I am busy for a long time .... This map has been fully implemented on a temporary basis. I have painted the first map several times. Basically, the terrain drawn each time is completely different, so I will not explain it much, let's take a rough picture of the scenario:

It looks simple, right? Alas ...... Enable the editor. If you are wandering in the scene, you can easily find that the character jumping function is defective, that is, the beating speed is too fast, and the camera is shining .....

Facts prove that laziness is not feasible ...... Now let's change the playercontrol script.

In the move function of the script, the original skip function has only two lines, that is, to determine whether the character is on the ground. In this case, the character is raised up to a certain distance, as a result, the jump is too abrupt.

Now, you can comment out and delete the if statement that determines whether the role is on the ground.

To make the jump not so abrupt, my idea is to define a bool variable. When the role presses the Space key on the ground, the variable is true, otherwise, when the role jumps above a certain height, it is false. I want to determine the height by using the ray detection method (of course, A useless error experiment won't be written ).

First, define a bool variable on the start function:

# Region determine private bool m_jumptmp = true; // determine whether a jump can be made # endregion // After the player presses a space, define a temporary variable to store the role in the downward direction, then judge whether the role is on the ground. If the role is on the ground, you can pick it up. Otherwise, after jumping over 1.5 meters, you have to wait until the jump is made: If (input. getkey (keycode. space) {vector3 m_direction = m_transform.transformdirection (vector3.down); // If (m_controller.isgrounded) {m_jumptmp = true;} else if (! Physics. raycast (m_transform.position, m_direction, 1.5f) // determine the hop height {m_jumptmp = false;} If (m_jumptmp) {SKIP ("jump2"); m_transform.translate (vector3.up * m_jump * time. deltatime );}}

The reason for writing things in the Space key is to save some performance. After the code is changed, return to the game and try again. The jump is much slower.

Related Article

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.