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

How to get an array of transforms and move GameObject for certain duration to that transforms list

Discussion in 'Scripting' started by Clintonsanto, Nov 26, 2015.

  1. Clintonsanto

    Clintonsanto

    Joined:
    Oct 14, 2015
    Posts:
    16
    Hi again..

    lets go right to the point!
    so here i want to make player skill similarly more like (Ciri's Blinking Skill = The Witcher 3 game) or (Omnislash = Juggernaut's Dota Hero Skill)
    but bit different.

    so specifically the logic is:

    on Getbutton ("Fire")

    i want to get an array list of "enemies" gameobject around player's radius and store it (tried using overlapsphere)
    then get the transforms position of those gameobjects again store it

    then automatically it'll move the player position between those all array of transform.positions
    either consecutively or in random orders for a set of duration and intervals.. i.e keep moving/blinking the player for as long as 10sec and giving 1sec intervals for each, before moving to next transform into another position on the array list

    if the time end before the list are complete then return to starting position (inCase the list was more than 10enemies bcs its only 10sec and 1sec between next transform)
    or if the list of enemies are fewer than 10 then back to array[0] on the list and repeat until the timers end
    orrrr if the enemies all dead before the timer end just return immediately

    and if it possible i want to add additional random XYZ value to each transform on the list so the player doesn't move exactly to the enemies position but only behind,beside,above or below them.

    here's what code i already tried

    Code (CSharp):
    1. bool isBlinking;
    2. RigidBody playerRB;
    3.  
    4. void Update()
    5. {
    6.     if (input.GetButton ("Fire1"))
    7.     {
    8.         Seeking();
    9.         isBlinking = true;
    10.         invoke("blinkfalse",10f);
    11.     }
    12. }
    13.  
    14. void blinkfalse(){
    15.     isBlinking = false;
    16. }
    17.  
    18.  
    19. void Seeking(){
    20.  
    21.     collider[] enemiesInRange = Physics.OverlapSphere(transform.position,blinkRadius)
    22.  
    23.     foreach (collider mobs in enemiesInRange)
    24.     {
    25.         if(mobs.isTrigger != true)
    26.         //bcs i had 2 colliders attached for each enemies 1 isTrigger 1 not
    27.         {  
    28.             EnemyHealth isEnemy = mobs.GetComponent <EnemyHealth>();
    29.             //to make sure its not environments
    30.             if(isEnemy != null)
    31.             {
    32.                 Transform target = isEnemy.GetComponent <Transform>();
    33.                 //get transform data for each gameobjects on the array
    34.                 if(isBlinking)
    35.                 {
    36.                     transform.position = Vector3.Lerp(playerRB.transform, target.transform,1f);
    37.                     //i expect it'll kept moving into each gameobjects transform each 1f before the "isBlinking" turn to false after 10sec
    38.                 }
    39.             }
    40.         }
    41.     }
    42. }
    but the result.. player is blinking only to one enemy on that array and not continuing into next transform on the array, i suspect it only the first one or straight to the last of the list. and had to wait for 10s after isBlinking return to false before i can press fire1 again well this one are actually intended for a limiter so the player won't kept jumpin around all day

    about the damage calculations.. i'll add it later after i know how to code about the movement properly

    if anyone got simpler method or more advanced coding please teach me
    because i doubt OverlapSphere are the best way to do so
    maybe even the worst bcs that is the only way i know to get info of our surrounding radius

    THANK YOU VERY MUCH
     
    Last edited: Nov 27, 2015
  2. Clintonsanto

    Clintonsanto

    Joined:
    Oct 14, 2015
    Posts:
    16
    *bump* really need enlightenment