Fine tuning instantiated bullet position

I have my airplane shooting bullets perfectly…woo hoo!!!

but they are instantiating a little too North of the image. slightly
would like them coming from the wing
how do you fine tune the instantiating position of an object?

I like to put a sub-object into my airplane prefab (an invisible GameObject as a child) that shows where the bullet is supposed to spawn. Instead of spawning at the player’s location, you spawn at that sub-objects location.

The best part about this is that your code, once you make this change, never has to change again for this, such as if you make a new plane with a gun in a different spot. You just change the gun muzzle offset, and the code keeps working.

EDIT: also, congrats on shooting!

oh thats brilliant and makes a whole lot of sense!!! back to the stalling problem tomorrow again. Thanks Kurt!

1 Like

Hey Kurt dude!!!

i did what you said, and created an empty gameobject calle BulletSpawnPosition

but in this line that insts my bullet

GameObject newBullet1 = Instantiate(bullet1, transform.position, transform.rotation);

i cant go

GameObject newBullet1 = Instantiate(bullet1, BulletSpawnPosition.position, transform.rotation);

BulletSpawnPosition isnt found, does it need a reference or something?

ok so i added

public GameObject BulletSpawnObject;

then put that replacing transform.position with BulletSpawnObject.transform.position

it works well when flying right, but not left…lol

Here we have discovered a minor limitation of the choice to flip sprites. BUT! There is a fairly quick workaround.

Instead of doing a sprite flip, which means nothing to your anchor point, do an actual scale flip on a sub-portion of your airplane, the part that contains the sprite(s).

Your script would need to get a reference to that “Flippable” sub-object, and instead of doing what it does with the Sprite Renderer (turning the toggle on and off), it would instead set the .localScale for the Flippable to be either (-1,1,1) (flipped) or (1,1,1) (not flipped.)

For sprites this will work fine, and it will also flip your spawn point. Here’s a sample hierarchy I threw up:

6411186--716022--Screen Shot 2020-10-12 at 4.06.23 PM.png

The GameObjects marked EMPTY don’t have anything on them, except the script one obviously.

Oh my goodness this looks very complicated