Offsetting Spawn Positions
Objective: Offset The Laser Spawning
As we can see in this example, we have our laser shooting from our ship now, but it’s shooting from the core of the ship, whereas you would probably want it to be being shot from the front of the ship.
To do this we can simply adjust our code for the spawning of the laser. First we want to see where we want our laser to spawn so we can go into our scene and place our ship and laser and reset the transforms on each.
Then we want to move the laser up to where we want it to actually spawn from.
If you are having different things impede your vision like the particle effects are doing here, you can simply turn off Gizmos so you don’t see those.
Now that you have the laser offset, you can see that I have offset it by 1.02 on the y axis of the position. What I would want to do next, is apply that into the code by creating a new vector 3 still spawning the laser from transform.position, but then adding the offset to the y axis.
The when spawning the Laser I would simply replace the transform.position and replace it with my laserSpawnOffset.
Now my laser is shooting from the front of my ship, not from the center of it anymore.