I am trying to create a weapon in a project I’m working on, and it’s mostly successful except for one issue that’s been plaguing me for days now. The prefabs that are instantiated by my weapon script are spawning side ways, not as in they are being fired side ways, but the orientation of the prefab itself is wrong.
Here’s the weapon code:
// defines the projectile prefab
public GameObject Projectile;
// defines the point at which the prefab is instantiated
public Transform MuzzlePoint;
// creates a short delay between shots
public float timeBetweenShots = 0.3333f;
private float timestamp;
void Update ()
{
if (Time.time >= timestamp &&(Input.GetButtonDown ("Fire1")) )
{
Instantiate(Projectile, MuzzlePoint.position, MuzzlePoint.rotation);
timestamp = Time.time + timeBetweenShots;
}
}
Here’s the code for the projectile:
public float thrust;
public GameObject ExplosionPrefab;
public GameObject FirePrefab;
public GameObject BloodExplosion;
void Start ()
{
GetComponent<Rigidbody>().velocity = gameObject.transform.forward * thrust;
}
void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.GetComponent<DmgHandler>() != null)
{
Instantiate(BloodExplosion, gameObject.transform.position, gameObject.transform.rotation);
collision.gameObject.GetComponent<DmgHandler>().ApplyDamage(37);
}
else
{
Instantiate(ExplosionPrefab, gameObject.transform.position, gameObject.transform.rotation);
Instantiate(FirePrefab, gameObject.transform.position, gameObject.transform.rotation);
}
Destroy(gameObject);
}
Any help would be greatly appreciated!!