Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Fish problem

Discussion in 'Scripting' started by JPCannon, May 9, 2015.

  1. JPCannon

    JPCannon

    Joined:
    Sep 25, 2013
    Posts:
    37
    Hi. I`m trying create script with spawn fish. It shoud be spawn on front of the ship way on the see. My problem is with this position. When ship is twisting, axis stay the same so if i write to spawn fish for example ship.transform.position.x + 30, if ship twist it will spawn next to ship not in front of it. Is any way to get private axis not in world way only in local?
     
  2. Fajlworks

    Fajlworks

    Joined:
    Sep 8, 2014
    Posts:
    344
    Try:
    Code (CSharp):
    1. Transform spawner = GetComponent<Transform>();
    2. float distance = 1.0f;
    3.  
    4. Vector3 spawnPosition = spawner.position + spawner.forward * distance;
     
  3. JPCannon

    JPCannon

    Joined:
    Sep 25, 2013
    Posts:
    37
    Great that works. My big mistake was that i change prefab position after instantiate, not befor it :p Great thx!