Unity Ladder Generation algorithm

Source: Internet
Author: User

The implementation of Unity's build ladder algorithm. 1. The ladder shape can be set by creating the angle dynamically from the prefabricated object.1.1 mainly involves the transformation of mathematical knowledge points, angles and radians.

    radians = angle multiplied by pi and divided by 180

Angle = radians divided by π and multiplied by 180.

1.2 Trigonometric Functions

Here only the tangent function tan is used, and the simple reasoning logic is as follows:

    

2.1 Below begins to look at the code PadelCreate.cs
1 usingUnityengine;2 usingSystem.Collections;3 4 5  Public classPadelcreate:monobehaviour6 {7      PublicGameobject Prb_padel;8      Public floatAngel = -;9     PrivateVector3 lastoneposition;Ten     //Use this for initialization One     voidStart () A     { - Anyangelpadel (angel); -     } the  -     /// <summary> -     ///stair instances of any angle -     /// </summary> +     /// <param name= "Angel" ></param> -     voidAnyangelpadel (floatAngel) +     { A         floatHudu = (Angel/ the) *Mathf.pi; at         //up the stairs. -          for(inti =0; I <7; i++) -         { -Gameobject Tmppadel =(Gameobject) instantiate (Prb_padel); -             floatyy = i *Mathf.tan (Hudu); -TmpPadel.transform.position =NewVector3 (-7+ I,-2+ yy,0); inLastoneposition =tmpPadel.transform.position; -         } to         //generate two horizontal directions +          for(inti =0; I <2; i++) -         { theGameobject Tmppadel =(Gameobject) instantiate (Prb_padel); *TmpPadel.transform.position =NewVector3 (lastoneposition.x+1, LASTONEPOSITION.Y,0); $Lastoneposition =tmpPadel.transform.position;Panax Notoginseng         } -         //Down Stairs the          for(inti =0; I <7; i++) +         { AGameobject Tmppadel =(Gameobject) instantiate (Prb_padel); the             floatyy = i *Mathf.tan (Hudu); +TmpPadel.transform.position =NewVector3 (lastoneposition.x +i, Lastoneposition.y-yy,0); -             //lastoneposition = tmpPadel.transform.position; $         } $  -     } -      the}

The structure of unity is as follows:

  

The preparation is complete, run it in unity!

  

The drawing is complete.

Unity Ladder Generation algorithm

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.