- Home /
2d move object relative to its rotation/place random on specified line?
Hi,
I am making a game where there are objects outside a circle. I need the objects a random distance away from the circle. The objects are rotated to look at the circle, but I am stumped. I have no idea how to make them be a random distance away from the circle based on their rotation.
This picture demonstrates what i am trying to do. I need the cubes to be anywhere along the red lines, but have no idea how to do it.
Any help is greatly appreciated, thanks.
Try this:
public float y$$anonymous$$in;
public float y$$anonymous$$ax;
float yDistance = Random.Range(y$$anonymous$$in, y$$anonymous$$ax);
Vector3 move= new Vector3(transform.position.x, yDistance, 0.0f);
transform.Translate(move);
This might work. Give it a try!
I seemed to have figured it out using a similar method.
I did
tranform.Translate(Vector2.right * Random.Range(0,5));
Thanks for your reply :)
Your answer
Follow this Question
Related Questions
How to change the rotation of the circle spawn? 1 Answer
Randomize shape.rotation for a particle emitter shape, sub emitter instance 1 Answer
How to Rotate Relative To World 1 Answer
Rotate object in 90 degrees relative to camera. 1 Answer
Random rotation of instantiated prefab along one axis 2 Answers