Parabolic movement doing strange things with certain angles

Hello,

so I’m trying to move a Sphere or whatever in a parabolic trajectory. There is no target or anything, just gravity, angle and speed at which the sphere begins moving.

This is the code I’m using:

using UnityEngine;

using System.Collections;

 

public class Parabola : MonoBehaviour {
	#region Public Variables
	public float gravity;
	public float angle;
	public float speed;
	public bool showVel = false;
	#endregion 
	Transform tr;
	float time;
	Vector3 pos;
	void Start() {
		tr = transform;
		pos = tr.position;
		time = 0;
		StartCoroutine("ParabolaStart");
	}
	void FixedUpdate() {
		time += Time.deltaTime;
		
	}
	IEnumerator ParabolaStart() {
		while (true) {
			float vel = (speed * Mathf.Sin(angle)) - (gravity * time);
			if (showVel)
				print ("VEL PARABOLA: "+vel);
			float x = 0 + (speed * Mathf.Cos(angle) * time);
			float y = 0 + (speed * Mathf.Sin(angle) * time) - (0.5f * gravity * Mathf.Pow(time,2f));
			tr.position = new Vector3(x,y,pos.z);
			
			
			yield return 0;
		}
	}
	void OnCollisionEnter(Collision col) {
		print ("Collided with: "+col.transform.name);
		StopCoroutine("ParabolaStart");
	}
	
}

The thing, it only seems to work with an angle in the 45~ range. The others I tried don’t, the Sphere just slightly moves, if anything at all.

Am I missing something or doesn’t it work that way in Unity?

I cannot be sure since you did not include your variable initializations, but I’ll bet you are passing degrees to the Sin() and Cos() functions. They take radians. So it will be:

     float x = 0 + (speed * Mathf.Cos(angle * Mathf.Deg2Rad) * time);