I want to make shoot system ,i have made a script but the bullet go in one direction only
i want the bullet go with the gun in all direction when the gun move
thanks,
`using UnityEngine;
using System.Collections;
public class Shoot : MonoBehaviour {
public GameObject bullet;
public Transform spawnPoint;
public float speed = 50;
public float rate = 1;
private bool canShoot = true;
//--------------------------
//--------------------------
public void ShootBullets(){
//shoot at every rate second(defulat every 1 sec)
if(canShoot){
canShoot = false;
Invoke("Reset", rate);
GameObject bulletClone = (GameObject)Instantiate(bullet, spawnPoint.position, Quaternion.Euler(90, 0, 0));
bulletClone.rigidbody.velocity = (-spawnPoint.up * speed) + rigidbody.velocity;
}
}
//----------------------------
//-----------------------------
private void Reset(){
canShoot = true;
}
I believe the problem is a combination of the answer above and the rotation you are setting. As your code stands, you are setting your rotation as
Quaternion.Euler(90, 0, 0)
No matter what. That means that -spawnPoint.forward will always be the same direction (the projectile is always spawned in the same rotation / facing).
I think you’re going to want to spawn your projectile more like this (EXAMPLE):