Search Unity

Firing bullets in a triangle shape?

Discussion in 'Scripting' started by RaulG, Jan 31, 2015.

  1. RaulG

    RaulG

    Joined:
    May 31, 2013
    Posts:
    74
    Don't know where to start with this, and I'm having trouble finding docs or Tutorials on it. So was wondering if anyone else had some info on where to start or docs to share.

    Ill edit this as I finish up some example code.


    IEnumerator Live()
    {
    while (true)
    {

    Vector3 mainPos = this.transform.position;
    Vector3 negXY = new Vector3(this.transform.position.x - 8.0f,
    0.0f,
    0.0f);
    Vector3 posXY = new Vector3(this.transform.position.x + 8.0f,
    0.0f,
    0.0f);
    allPos.Add(mainPos);
    allPos.Add(negXY);
    allPos.Add(posXY);

    for (int i = 0; i < Points; i++)
    {
    GameObject bClone = Instantiate(Bullet, allPos,Quaternion.identity) as GameObject;
    }
    yield return new WaitForSeconds (100);
    }
    }


    That basically gives me the 3 points of the triangle.

    Now I just need to fill it..

    So...

    Another for loop?
     
    Last edited: Jan 31, 2015
  2. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,697
    Well, you would need 3 points. And 3 angles. You have the first point, all you need is to determine when the second point (in time) occurs, thus its position. You would have to base the rest of the angles off of this info.

    You could of course preset all this to make your life easy.
     
  3. RaulG

    RaulG

    Joined:
    May 31, 2013
    Posts:
    74
    It's kind of in a state where it just explodes everywhere.. Im using the Instantiate in a Circle from the Docs as a base.
     
  4. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,697
    What determines the change of direction?
     
  5. RaulG

    RaulG

    Joined:
    May 31, 2013
    Posts:
    74
    I dont even really know..
     
  6. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,697
    Hm. Well, it could hit a wall for instance, or, travel a certain distance.
     
  7. RaulG

    RaulG

    Joined:
    May 31, 2013
    Posts:
    74
    I was thinking of using something like Mathf.Lerp or Smoothstep to shift between the bottom two points of the triangle. The top point being where it starts at.
     
  8. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,697
    Do you know the shape of the triangle before hand? Is the size, form, shape etc, consistent, or is it random? Do you need to know the shape before you fire it? Or does the first hit, determine the shape??
     
  9. RaulG

    RaulG

    Joined:
    May 31, 2013
    Posts:
    74
    Well no, but it should stay the consistent shape throughout.

    As for if i need to know it before hand, hmm, I believe so, so that I can change it to fit the level.
     
  10. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,697
    I think you need to consider what causes the first change in direction. Then, once you know that, you can measure the distance of the first side.

    Knowing a triangle is made up of 180 degrees, divided by 3 angles, you can start to figure the rest out.
     
  11. RaulG

    RaulG

    Joined:
    May 31, 2013
    Posts:
    74
    You're giving me way to much credit...

    With that Ill see what I can do..

    Also I think you meant 90
     
    Last edited: Jan 31, 2015
  12. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,697
    One triangle, made up of 3 angles. The 3 angles add up to 180 degrees. Always.
    Math yo. It's awesome.
     
  13. RaulG

    RaulG

    Joined:
    May 31, 2013
    Posts:
    74

    Ill just look for info somewhere else...