Question by 
               Crystite · Feb 17, 2017 at 09:59 PM · 
                unity 5scripting problemrigidbodyinstantiatevelocity  
              
 
              Bullet not inheriting speed of player.
Hello!
I'm instantiating a bullet at my spawner location, setting it's velocity to that of my player and then adding force either left, -left, up, -up. It is working fine without the inheritance only when shooting right.
I've been coding and doing art all day so I'm a bit out of it, sorry if it's something simple.
This is the code: 
Snippet:
         if (Input.GetKey(KeyCode.RightArrow) && attackReset)
         {
             GameObject bullet;
             bullet = Instantiate(playerProjectile, projectileSpawn.transform.position, projectileSpawn.transform.rotation);
             bullet.GetComponent<Rigidbody2D>().velocity = rb2d.velocity / bulletInheritance;
             bullet.GetComponent<Rigidbody2D>().AddForce(bullet.transform.right * playerProjectileSpeed);
             attackReset = false;
         }
         if (Input.GetKey(KeyCode.LeftArrow) && attackReset)
         {
             GameObject bullet;
             bullet = Instantiate(playerProjectile, projectileSpawn.transform.position, projectileSpawn.transform.rotation);
             bullet.GetComponent<Rigidbody2D>().velocity = rb2d.velocity / bulletInheritance;
             bullet.GetComponent<Rigidbody2D>().AddForce(bullet.transform.right * playerProjectileSpeed * -1);
             attackReset = false;
         }
   
 
               In this instance the inheritance/velocity set works for the right arrowkey but the left arrowkey doesn't inherit anything...
Very confused and tired, hopefully an answer by morning. Goodnight!
 
                 
                devenv-2017-02-17-01-33-21.png 
                (52.5 kB) 
               
 
              
               Comment
              
 
               
              Your answer