Parabola angle doesn't work

I wanted to make a "kogelbaan" (wiki links it to the english "Trajectory of a projectile")

I used alt text and alt text for the parabola. but when I try to chance the angle from 45 to 44 or 46 is doesn't do as expected. What did I do wrong?

in my code I used dutch words(hoek = angle, tijd = time, kracht = force, kogel = bullet)

    public GameObject kogel;
private float tijd;
private float hoek = 45f;
private float kracht = 1f;
public int aantalkogels = 1;

// Use this for initialization
void Start () {
    for (int i = 0; i < aantalkogels; i++)
    {
        GameObject kloonkogel = (GameObject)Instantiate(kogel);
        kloonkogel.name = "Kogel"+(i+1);
    }
}

// Update is called once per frame
void Update () {
    tijd = Time.timeSinceLevelLoad;

    for (int i = 0; i < aantalkogels; i++)
    {
        GameObject active = GameObject.Find("Kogel"+(i+1));
        if (active != null)
        {
            active.transform.position = new Vector3(kracht * (Mathf.Cos(hoek)* Mathf.Rad2Deg) * tijd, (kracht * (Mathf.Sin(hoek)*Mathf.Rad2Deg) * tijd - (5)*(tijd * tijd)) + (15 * i));
            if(active.transform.position.y < 0)
            {
                //DestroyObject(active);
            }
        }
    }
}

1 Answer

1

The way I see your calculation, you're trying to convert some angle (hoek?) from radians to degrees after you take the cosine of it? I don't understand how that makes any sense. :) The argument of Mathf.Cos should be in radians indeed. So if hoek is an angle measured in degrees, then you need to convert it to radians before you take the cosine (and the following sine, for that matter). I.e. it inside the parenthesis:

Mathf.Cos(hoek*Mathf.Deg2Rad)

And not,

Mathf.Cos(hoek)* Mathf.Deg2Rad

angle = hoek. I want that people can give a angle and a force and that they need to try to get the bullet to hit the target.