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

Question Bullet instantiation - local coordinates and movement

Discussion in '2D' started by NikkiSIF, Jun 18, 2020.

  1. NikkiSIF

    NikkiSIF

    Joined:
    May 15, 2020
    Posts:
    14
    Hi, I'd need some explanation on how to correctly instantiate a bullet and it's movement in my 2d iso game.

    I have a player gameobjects. It has a script 2Dcontroller, and it has as child a Aim gameObject that I use to get the mouse position to rotate the Weapon.

    The weapon gameObject is some kind of container which will have several weapons as child. I attached to the weapon gameObject a script that instantiate a bullet. This bullet appears at the top level of the hierarchy, so it doesn't inheritate of the weapon gameObject angle.
    What is the best way to structure the hierarchy to make the bullet inheritate of the aim direction?

    I don't know if I'm clear enough, please ask me details if needed.

    Thx!
     
  2. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    2,637
    @NikkiSIF

    "What is the best way to structure the hierarchy to make the bullet inheritate of the aim direction?"

    Hierarchy doesn't matter and you probably don't want bullet to be part of your weapon's hierarchy. You simply set the bullet rotation to your container object rotation. Google unity shoot bullets for tutorials or RTFM as there is an example how to set rotation:

    https://docs.unity3d.com/ScriptReference/Object.Instantiate.html
     
  3. NikkiSIF

    NikkiSIF

    Joined:
    May 15, 2020
    Posts:
    14
    Thanks, that's actually what I did in the meantime and it worked! (I should have done this before posting i guess... )