Sitting like 3 hours and can’t get that.
The code is very sipmle. The short version is:
public GameObject bullet; // in general class
rbBullet = bullet.GetComponent(); // in Start()
Instantiate(bullet, spawnPos.position, spawnPos.rotation); // in Update
rbBullet.AddForce(new Vector2(10f, 0)); // in Update
Doesn’t work… Bullets appear and stay where they are.
I am stupid?
Your rbBullet call to get the component is wrong…
First you should declare either a public or private Rigidbody2D, like you have with GameObject bullet.
private Rigidbody2D rbBullet;
Then the GetComponent call in Start should be:
rbBullet = bullet.GetComponent<Rigidbody2D>(); //Make sure this Gameobject has a Rigidbody2d attached
Normally you would instantiate the bullet from another script, and the Bullet behaviour would be on the bullet prefab itself.