I am working on this 2d top down shooter and cannot get the shooting mechanics to work. The bullets spawn in the correct rotation and position but they do not move at all. nothing.
I would very much appreciate it if someone could tell me what I am doing wrong.
if (Input.GetButtonDown ("Fire1")) {
if (currentWeapon == 1 & pistolAmmo >= 1){
GameObject Bullet = (GameObject)Instantiate(Projectile, playerSprite.transform.position, player.transform.rotation);
Bullet.GetComponent<Rigidbody>().AddForce(player.transform.forward * bulletSpeed * Time.deltaTime);
}
I can post the rest of the code if it will help. Thank you in advance.
P.S Sorry for bad English
BiG
July 23, 2015, 12:17pm
2
As a starting point, make sure that your bullets have a non-kinematic rigidbody.
The line
GameObject Bullet = (GameObject)Instantiate(Projectile, playerSprite.transform.position, player.transform.rotation);
should be
Rigidbody Bullet = Instantiate(Projectile, playerSprite.transform.position, player.transform.rotation) as Rigidbody;
Spawn the object as a Rigidbody and then apply force that way.
if (Input.GetButtonDown ("Fire1")) {
if (currentWeapon == 1 & pistolAmmo >= 1){
Rigidbody Bullet = Instantiate(Projectile, playerSprite.transform.position, player.transform.rotation) as Rigidbody;
Bullet.GetComponent<Rigidbody>().AddForce(player.transform.forward * bulletSpeed * Time.deltaTime);
}