- Home /
Gun doesn't shoot straight?
Hello, I just added a new gun in my fps game and I attached the same script to my new gun as to my previous weapons which work fine. I obviously changed the variables so that they fit my new gun, but all the code is the same: var projectilePrefab : Transform; var force : float = 20000; static var mg36clipSize : int = 100; var mg36fullClip : int = 100; var projectile; var font : Font; var scopeCam : Camera;
function Awake (){
mg36clipSize = mg36fullClip;
}
function Update () {
scopeCam.gameObject.active = false;
if (Input.GetButton("Fire1") && mg36clipSize > 0){
mg36clipSize--;
projectile = Instantiate (projectilePrefab,
GameObject.Find("mg36_spawnPoint").transform.position,
GameObject.Find ("First Person Controller").transform.rotation);
projectile.rigidbody.AddForce (projectile.transform.right * force);
wait();
}
}
function OnGUI (){
GUI.skin.font = font;
GUI.contentColor = Color.red;
GUI.Label (Rect (10,600,100,100), "" + mg36clipSize);
}
function wait (){
yield WaitForSeconds (0.2);
}
However, on this gun, when I shoot the projectile goes off to the side for some reason. Does anyone know how this can be fixed? Thanks a lot, its probably just a really stupid problem but I'm a noob ;)
projectile.rigidbody.AddForce (projectile.transform.right * force);
Apparently shoots it off to the right ins$$anonymous$$d of forward.
Your answer
Follow this Question
Related Questions
FPS Scripting Problems 2 Answers
Some issues with weapon switching and reloading? 2 Answers
crosshair scrip not working 1 Answer
gun rotation fps 0 Answers
Do raycasts only collide with colliders or can I detect a hit through something else? 2 Answers