Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Having trouble spawning objects in a circle

Discussion in '2D' started by Midoorabi, Aug 31, 2015.

  1. Midoorabi

    Midoorabi

    Joined:
    Feb 18, 2015
    Posts:
    2
    I'm trying to make bullets spawn arround my Player and shoot in every direction ... i did all the math with a sheet of paper but my script isn't working
    here it is
    Code (JavaScript):
    1. function SpecialAbility(radius:float){
    2.     var a: float = transform.position.x;
    3.     var b: float = transform.position.y;
    4.    
    5.     for (var x:float = -radius+a; x < radius+a+0.1; x+= 0.1){
    6.         var position: Vector2;
    7.         position.x = x;
    8.         var ax: float = -2*a*x;
    9.         var bb:float = 2*b;
    10.         var numerator: float = Mathf.Pow(x,2) + ax + Mathf.Pow(a,2) + Mathf.Pow(b,2) - Mathf.Pow(radius,2);
    11.         var dinominator: float = 1 + bb;
    12.         position.y = numerator/dinominator;
    13.         Instantiate(bullet, position, Quaternion.Euler(0,0,0));
    14.         if (x != radius+a || x != -radius+a){
    15.             position.y *= -1;
    16.             Instantiate(bullet, position, Quaternion.Euler(0,0,0));
    17.         }
    18.     }
    19. }
     
  2. Midoorabi

    Midoorabi

    Joined:
    Feb 18, 2015
    Posts:
    2
    SOLVED