Answers for "How can I launch a ball given an angle in degrees and a magnitude?"
http://answers.unity.com/questions/1677508/how-can-i-launch-a-ball-given-an-angle-in-degrees.html
The latest answers for the question "How can I launch a ball given an angle in degrees and a magnitude?"Answer by Captain_Pineapple
http://answers.unity.com/answers/1677536/view.html
Hey there,
in general your mistake is common one: you did not read the documentation ;)
Mathf.Cos does not take degree but radians as input. so multiply by 3.141/180.0 and you are good to go.
<br>
a way to make your code a bit more smooth:
void Explode(int count)
{
Vector2 spawnLoc = rigidbody2d.position;
Debug.Log("Exploded into " + count + " parts");
float angleInc = 6.282f / count;
for (int i = 0; i < count; i++)
{
Vector2 direction = new Vector2(Mathf.Cos(angleInc * i),Mathf.Sin(angleInc * i))*speed;
GameObject smallBall = Instantiate(ball, spawnLoc, Quaternion.identity);
smallBall.GetComponent<Rigidbody2D>().velocity = direction;
}
Destroy(gameObject);
}
<br>
also you **need** to read into object pooling. Always instantiating and destroying objects will lead to a performance issue sooner or later.Tue, 12 Nov 2019 08:48:13 GMTCaptain_PineappleAnswer by BastianUrbach
http://answers.unity.com/answers/1677531/view.html
Mathf.Sin and Mathf.Cos use radians, not degrees. You should multiply *degree* with Mathf.Deg2Rad. Also, the .normalized is unnecessary, *vector* already has a length of 1.Tue, 12 Nov 2019 08:33:57 GMTBastianUrbach