Projectiles will only fire correctly between 42 and 50 degrees, any other angle that i have tried sends them either directly down or backwards. Please take a look at the code:
using UnityEngine;
using System.Collections;
public class Cannon : MonoBehaviour {
public GameObject projectilePrefab;
public int Angle = 10;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void FixedUpdate()
{
if (Input.GetButtonDown("Fire1"))
{
GameObject projectile = Instantiate(projectilePrefab, transform.position, transform.rotation) as GameObject;
projectile.rigidbody.AddRelativeForce(new Vector3(0, 0, -1000));
}
}
void LateUpdate()
{
transform.rotation = Quaternion.Euler(Angle, 0, 0);
}
}