Question by
Promethium61 · Aug 20, 2016 at 09:44 AM ·
bulletgunfire
I have attached this script onto my gun object bu the bullet only fires in one direction,I have attached this code my gun but the bullet only fires in one direction
using System; using UnityEngine; public class ShootMissle : MonoBehaviour {
public GameObject spawnPoint;
public GameObject ExplosionPrefab;
public Rigidbody projectilePrefab;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if(Input.GetButtonDown("Fire1"))
{
Rigidbody hitPlayer;
hitPlayer = Instantiate(projectilePrefab, transform.position, transform.rotation) as Rigidbody;
hitPlayer.velocity = transform.TransformDirection(Vector3.forward * 100);
// Physics.IgnoreCollision ( projectilePrefab.collider, transform.root.collider );
}
for(var i =0; i < Input.touchCount; ++i)
{
if(Input.GetTouch(i).phase == TouchPhase.Began )
{
Rigidbody clone;
clone = Instantiate(projectilePrefab, transform.position, transform.rotation) as Rigidbody;
clone.velocity = transform.TransformDirection(Vector3.forward * 200);
// Physics.IgnoreCollision ( projectilePrefab.collider, transform.root.collider );
}
}
}
}
,
Comment
Answer by OsmiousH · Aug 20, 2016 at 10:54 AM
In line 30 of your script try the easy way
clone = Instantiate(projectilePrefab);
What does this do?
it just instantiates the object with the rotation and position of the current object
Your answer
Follow this Question
Related Questions
How do I instantiate an objects direction and speed seperately? 1 Answer
2D Bullet Not Working 1 Answer
Bullet does not move forward 0 Answers
Teleporting To Projectile Location 1 Answer
Trying to make a gun, but it wont work? Please help. 1 Answer