Reply To: UNIT SPACE SHOOTER….The shot spawn stays at fixed location and doesn’t move with ship.

Forum Archive UNIT SPACE SHOOTER….The shot spawn stays at fixed location and doesn’t move with ship. Reply To: UNIT SPACE SHOOTER….The shot spawn stays at fixed location and doesn’t move with ship.

#32110
Jonathan Gonzalez
Participant

    According to your script that’s exactly what it should be doing. In your script you’re instantiating the shot game object at the location of where the spawn shot is at. If you want the shot to originate from the ship, make the spawn shot a child of the ship. I can see from your screenshot that it’s a separate object and not part of the ship hierarchy. I assume that’s the only issue. 

    A few things I would change in your script for ease of use and to cut down a few lines/words. First, since the shot spawn is just used for positioning use it as a Transform. 

    Transform shotSpawn;

    That way you can just say shotSpawn.position instead of shotSpawn.transform.position. If you are using it as a GameObject somewhere else then disregard this. 

    You can also simplify the Instantiation lines to one line:

    Instantiate(shot, shotSpawn.position, Quaternion.identity) as GameObject;

    With that line you’re instantiating your shot and positioning it at the shotSpawn position. The Quaternion.identity part just means you’re not rotating the shot from it’s original rotation. If you wanted to rotate it to the same rotation as the shotSpawn you’d write instead shotSpawn.rotation in that spot. 

    If you have any other questions let me know.