I have a top-down 2D space shooter. To rotate my ship I use angles. So to fire bullets I have to get x and y to use rigidbody2D.AddForce(). I use this code:
void Update () {
GameObject instance = (GameObject)Instantiate (Resources.Load ("Bullet"), bulletSpawn.transform.position, bulletSpawn.transform.rotation);
instance.rigidbody2D.AddForce (new Vector2 ((bulletSpawn.transform.position.x - transform.position.x)*shotPower, (bulletSpawn.transform.position.y - transform.position.y)*shotPower));
}
//bulletSpawn is the GameObject in the front of my ship, where I fire bullets from. Script is attached to the ship.
The code works fine. The only problem is that when the ship goes fast, the shots are fired not in the way they are intended to (they go more left the faster you go). Hope at least someone will understand this. Sorry for crude grammar.