Search Unity

Question 5 Side Pentagon with Prefabs

Discussion in 'Scripting' started by MaximilianPs, Jun 30, 2021.

  1. MaximilianPs

    MaximilianPs

    Joined:
    Nov 7, 2011
    Posts:
    322
    Hello, I need a genius in trigonometry and c # who can help me to solve a problem:
    I need to create a boundary wall that uses wall pieces (prefabs) with a length 15 Unity's units.

    We can use all the pieces that we need, but they cannot be resized (the ideal in the least case would be 3 per side), so the method I need, must consider the size of the walls and also the size of the city that will sit.

    I've made some tests but I'm not very good at math, so I definitely need help! :rolleyes:o_O
     
  2. RadRedPanda

    RadRedPanda

    Joined:
    May 9, 2018
    Posts:
    1,647
    360 / 5 = 72

    So each wall's angle is 72n, where n is the number of the wall (starting at 0)

    Then you would need to get the distance from your origin point for each wall.

    We know each angle of a regular pentagon is 108 degrees, so half of that is 54 degrees.

    72 / 2 = 36, which gives us a triangle with angles 36, 54, and 90

    We can say the length of a wall is x (which is your 15 Unity units), and half of the wall is x/2.

    Using the law of sines, we can get that sin(54)/(x/2) = sin(36)/(y), where y is our distance from the center.

    Solve for that and you get the magnitude for each of your distances.
     
    Bunny83 likes this.
  3. MaximilianPs

    MaximilianPs

    Joined:
    Nov 7, 2011
    Posts:
    322
    First of all thank you for the explication
    But also o_O I'm still pretty confused

    upload_2021-7-1_10-0-18.png

    So starting from the fact that TownSize define the inside city dimension, I have to calculate the angle of the first wall on the left, and then cycle for each angle in clockwise?... I'm right?
    Also, rotate a wall sin't enough 'cause I have to make sure that the extreme point of the wall that we have rotated coincides with the base of the pentagon.

    And here starts all my issue
     
  4. MaximilianPs

    MaximilianPs

    Joined:
    Nov 7, 2011
    Posts:
    322
    I've found a solution, but still won't help me 'cause it scale the walls instead of instantiating the required number of walls. :confused:

     
    Last edited: Jul 1, 2021