How do I offset a bullet from my player?
So I copied this from a yt video so I have no idea what I'm looking at
GameObject instCharge1 = Instantiate(Charge1, transform.position, Quaternion.identity) as GameObject;
Rigidbody2D instCharge1Rigidbody2D = instCharge1.GetComponent();
instCharge1Rigidbody2D.AddForce(Vector3.forward * speed1);
Anyway, the bullet Charge1
spawns inside the player, so the only way to spawn one is when I'm going fast enough for the game to not keep up. It's a 2d game, both player and bullet have Rigidbody2D
/BoxCollider
. I just need to know what part I can tweak for x/y offsets.
Thanks!
Answer by Monsoonexe · Feb 21 at 12:19 AM
In the class fields of the shooter, have something like public Transform bulletSpawnPoint;
. Create a new empty GameObject as a child of the gun barrel (or wherever the bullets spawn from), and assign the new gameObject to the bulletSpawnPoint
.
Then change the code to Instantiate(Charge1, bulletSpawnPoint.position, Quaternion.identity)
.
It works, but the bullet won't move at all, regardless the speed when it's placed
Your answer
![](https://koobas.hobune.stream/wayback/20220613053143im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Problems with respawning using a very simple script 1 Answer
How to display random questions without repeating the previous? 2 Answers
Inherance script problem [C#] 0 Answers
Performance Issue While Near One Specific Object 0 Answers
How do I make my player model rotate based on the direction he is walking. 0 Answers