Bullet instantiates inside of character sprite towards mouse instead of outside.

Currently working on a Top down Twin-stick Arena Survival game and I’m currently stuck on the instantiating of my bullets when they shoot to the mouse’s direction. Currently they’re spawning inside of the main character, which I suspect is the transform.position. However the way I want the bullet to instantiate is just outside of the character sprite.

Rigidbody2D bPrefab = Instantiate (bulletPrefab, transform.position,
transform.rotation) as Rigidbody2D;
bPrefab.rigidbody2D.AddForce (mouseDir * bulletSpeed * 300);

Any Ideas?

you want to instantiate the bullet a little bit out from the transform.position, and you can do it like this:

float distance = 1.5f;
Transform bulletStartPos = transform.position + (Vector3.forward * distance);

Rigidbody2D bPrefab = Instantiate (bulletPrefab, bulletStartPos, transform.rotation) as Rigidbody2D;

// .. blah blah

Change distance variable depending on what works best. Also Vector3.forward can be changed to up or right etc.)