Question by
LorenzoNeriAIR · Jan 08, 2018 at 03:13 PM ·
rotationshooter2d rotation
2D shooter: shoot towards cannon rotation
I'm doing a 2D shooter: the cannon position is fixed, but the player can rotate the cannon. I would like to shoot the bullet toward the cannon's angle set, but the result is that the bullet prefab is rotated (the sprite itself) and being shot always as the cannon hans't been rotated.
This is the code I've used, but (of course) doesn't work:
GameObject bullet = Instantiate (this.bulletPrefab, transform.position, transform.rotation) as GameObject;
bullet.GetComponent<Rigidbody2D>().AddRelativeForce(transform.rotation.eulerAngles);
Comment