Hi,
I’m trying to rotate an empty game object with its children in a way that the selected child is in front to the camera:
I use this code for the task:
if(Input.GetKeyDown(KeyCode.A))
{
int x = Random.Range(0, direction.Length);
start = true;
startRotation = transform.rotation;
progress = speed;
targetRotation = Quaternion.LookRotation(direction[x].localPosition);
Debug.Log(direction[x].name + " " + targetRotation.ToString());
}
if (direction != null && start)
{
/* Debug.Log(progress);
Debug.Log(startRotation);
Debug.Log(targetRotation);*/
float str = Mathf.Min(0.5f * Time.deltaTime, 1);
transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, progress);
if(progress >= 1f)
{
transform.rotation = targetRotation;
start = false;
}
progress += speed;
}
It works perfect with the sphere, capsule and the “diamond” (upper cube), but the cylinder and the (normal) cube switch places when I get to them. The script chooses the cube but the cylinder comes to the front and visa verse.
The cube has the position (0, 0, 1) and the cylinder (0, 0, -1). I found out that this happens if the z value is different then 0. What can I do, that this code snip works as I want to ![]()
Thanks in advance
Alex