- Home /
Problem with Shooting Accuracy
I know such a problem being discussed billion of times but in my case still can't get the script to work properly. Here's a part of code applied to the character:
var Bullet : Transform;
var Speed = 1000;
var spawnPoint : Transform;
function Update (){
if
(Input.GetAxis ("Vertical") < 0.0 && (Input.GetButton ("Action")) && (Input.GetButton ("Aiming"))){
animation.CrossFade ("shoot_down");}
else {
if
(Input.GetAxis ("Vertical") > 0.0 && (Input.GetButton ("Action")) && (Input.GetButton ("Aiming"))){
animation.CrossFade ("shoot_up");}
else {
if
(Input.GetButton("Aiming")){
if
(Input.GetButton("Action")){
animation.CrossFade("shoot");}}
}
}
}
function Shoot(){
var Bullet=Instantiate(Bullet,GameObject.Find("spawnPoint").transform.position, Quaternion.identity);
Bullet.rigidbody.AddForce(transform.forward * Speed);
}
The reason I've created function Shoot is to get control over the shooting action through animation clips' events and it works pretty well for me. But I still can't give right direction to the bullet. It flies forward, according character's position and horizontal rotation, but when it comes up to perform up or down shootin' actions bullet unable to get "spawn point's" y-rotation coordinates and still fly forward. Meaning, it follows up or down to spawn point but the shot goes forward accordingly character's coordinates, but not exactly spawn point's (hand gun's) ones. Also tried transform.rotation instead of Quaternion.identity, but it did nothing. What can be wrong with the script? Thanks in advance for your assistance :)
Your answer
Follow this Question
Related Questions
Shooting script C# 1 Answer
shoot bullet on a moving gameobject 0 Answers
Spawn bullet in front of object then apply force? 1 Answer
rotation relative to a transform 1 Answer
Bullets Based on Orientation 1 Answer