- Home /
Question by
DeusPL · Dec 11, 2015 at 01:58 PM ·
unity 5rotationinstantiateshooting
Shooting bullets in different patterns
Hello, so I am coding this space shooter game and I am creating different weapons.
What I stumbled across is when I want my bullets to shot within rotated path I just cant make it work - I am just rotating the bullet prefab, not the path itself...
Check the screen - I am shooting in red line, but I want bullets to go like the blue lines.
My code for shooting straight:
public void Shoot() { GameObject bulletHolder = GameObject.Find("BulletHolder"); //find the bullet holder in stage
if (redWeapon == true)
{
GameObject bullet01 = (GameObject.Instantiate(PlayerBulletGO));
bullet01.transform.SetParent(bulletHolder.transform, false);
bullet01.transform.position = bulletPosition01.transform.position;
if (redWeaponLvl >= 1)
{
GameObject bullet02 = (GameObject.Instantiate(PlayerBulletGO));
bullet02.transform.SetParent(bulletHolder.transform, false);
bullet02.transform.position = bulletPosition02.transform.position;
}
And bullets move script:
void Update ()
{
//bullets current pos
Vector2 position = transform.position;
//calculate new pos
if(gameManager.GetComponent<GameManager>().movingFromRight == false)
{
position = new Vector2 (position.x, position.y + speed * Time.deltaTime);
}
else
position = new Vector2 (position.x + speed * Time.deltaTime, position.y);
transform.position = position;
Vector2 max = Camera.main.ViewportToWorldPoint (new Vector2 (1, 1));
if (transform.position.y > max.y || transform.position.x > max.x + 10f)
{
Destroy(gameObject);
}
}
Where to go from there?
Thanks people!
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612052059im_/https://answers.unity.com/themes/thub/images/avi.jpg)