[SOLVED]Same shooting bullet Script for all weapons
Hello ! I'm a begginer to unity and I'm making a simple FPS game and I have a problem with my shooting script.
I made several weapons (sub-machine gun, canon and pistol). My problem is with the direction the bullet goes. It changes from gun to gun and I would like to have a default shooting script for every gun (if it's possible ofcourse). The problem I suspect is the vector positions are messed up ( transform.up in one makes it go forward and the other is (-negative)transform.up when I use AddForce):
Simplifying, I need to have one line of code that Adds force to all guns in the same direction. (If it's not possible, will creating new weapons in the same direction as the canon and sub-machine work?)
For the sub-machine and canon it works if I use: ===================================
Bala_Temp.AddForce(transform.up X ForcaDaBala);
for the pistol it works if I use: ===================================================
Bala_Temp.AddForce(-transform.up X ForcaDaBala);
(I put X instead of * because it would mess the bold)
Thanks in advance ! :)
==============================Full script=====================================
if(Input.GetButtonDown("Fire1")){
GameObject Cano_Temp; // (Cano_Temp is where the bullet shoots from)
Cano_Temp = Instantiate(Bala,transform.position, transform.rotation) as GameObject;
Rigidbody Bala_Temp;
Bala_Temp = Cano_Temp.GetComponent<Rigidbody>();
//=====Problem is in the following lines below:=====
//Bala_Temp.AddForce(-transform.up * ForcaDaBala);//pistol
//Bala_Temp.AddForce(transform.up * ForcaDaBala);//canon and sub-machine
Answer by NunoDinisSantos · Feb 12, 2017 at 06:33 PM
I managed to fix the problem. I created a new pistol with the same vector transforms as the other two guns. It works now, but it still uses transform.up instead of transform.forward.
Your answer
![](https://koobas.hobune.stream/wayback/20220612110925im_/https://answers.unity.com/themes/thub/images/avi.jpg)