Hi! I am trying to get some 3d menu going.
I have found a script that does what i want - instantiate object around center in circle:
if(Input.GetKeyUp(KeyCode.LeftAlt))
{
var center = my3dCamera.transform.position;
for (i = 0; i < 5; i++)
{
var pos = RandomCircle(center, 2);
// make the object face the center
//var rot = Quaternion.FromToRotation(Vector3.forward, center-pos); //not needed
var clone = Instantiate(button, pos, transform.rotation); //rot
}
}
function RandomCircle(center:Vector3, radius:float): Vector3 {
// create random angle between 0 to 360 degrees
var ang = Random.value * 360;
var pos: Vector3;
pos.x = center.x + radius * Mathf.Sin(ang * Mathf.Deg2Rad);
pos.y = center.y + radius * Mathf.Cos(ang * Mathf.Deg2Rad);
pos.z = center.z;
return (pos);
}
i have attached this script to main camera.
Problem is that i cant get my camera local direction. center variable is always pointing in the world rotation(or direction). How can i pass “center” to RandomCircle function in it’s (camera this script is attachet to) local direction?
I have tried transform.localRotation, transform.TransformDirection, InverseTransformDirection, but nothing works. They are instantiated off screen, but always facing world coords.