Greetings and Salutations! I found this ‘Random insideUnit Circle’ code in the Unity Scripting documents. In my project my character throws a ball at a round target. I want the ball to hit the target some of the time, so I thought this random inside circle would be perfect. The example is not really clear on how to utilize this code.
public static var InsideUnitCircle:Vector2;
// Sets the position to be somewhere inside a circle
// with radius 5 and the center at zero.
var newPosition : Vector2 = Random.insideUnitCircle * 5;
transform.position.x = newPosition.x;
transform.position.y = newPosition.y;
I placed this code on the target, but the ball is not influenced by the script. The target actually is not even visible, it just disappears. Seems like there is no reference between the ball and the target. If I put it on an empty game object, there is no reference to anything. The following is my ‘throw the ball’ script.
var parentbone:GameObject;
var rigid:Rigidbody;
var lastPos:Vector3;
var curVel:Vector3;
function Start () {
transform.parent=parentbone.transform;
rigid.useGravity=false;
}
function Update () {
}
function ReleaseMe(){
transform.parent=null;
rigid.useGravity=true;
transform.rotation=parentbone.transform.rotation;
rigid.AddForce(transform.forward* 1000);
}
This throwing script works ok. I’m just aiming for a little more accuracy and consistency. No pun intended. Thus the randomness inside a set circle.
I’m probably using this code totally out of context, but it seems if I have a round target/circle that is smaller than 5 units the ball should hit the target some of the time. At least that is my goal. How can I achieve this goal and hit my target? I’m perfectly open to another way to skin this cat! Help!
Thanks!