I have a game where I am creating meteors to launch towards a planet in the middle of the screen. Right now I am creating meteors and adding force towards the center of the planet.
What I want to happen is that they should be launched with a random angle (within a certain amount), so they will potentially not even hit the planet. Basically I want to be able to change its direction to 30 or so degrees to the right or left of the planet. But I am having trouble finding out how I would do that. Here is what I currently have for launching a meteor straight at the planet:
GameObject m = Instantiate(obj, vect, Quaternion.identity); m.GetComponent<Rigidbody2D>().AddForce((Planet.transform.position - m.transform.position).normalized * 500); m.GetComponent<Rigidbody2D>().AddForce(transform.right * 200);
So I want to:
- Spawn a meteor object
- Aim meteor at the planet and add a variable angle accuracy
- Addforce to the meteor in that direction
Thank you in advance for any help.
Here is a quick illustration as well. The green circle is the planet and the purple circle is a meteor.
(Also I couldn’t space out this write up in the format I wanted, at least in the preview so I apologize if its jumbled)