- Home /
Question by
gfellisch · Nov 16, 2019 at 08:58 PM ·
transformmathpositioning
How do I position a GameObject to the right hand of the camera?
If the GameObejct is enabled, it should position itself to the right hand in front of the camera. Just like the cube in the picture.
This is what I tryed so far:
private float floorLevel 0.0f;
private void OnEnable()
{
Transform cameraTrans = Camera.main.transform;
transform.position = new Vector3(
cameraTrans.position.x + Mathf.Cos((cameraTrans.rotation.eulerAngles.y + angleToCamera) * Mathf.PI / 180),
floorLevel,
cameraTrans.position.z + Mathf.Sin((cameraTrans.rotation.eulerAngles.y + angleToCamera) * Mathf.PI / 180));
}
gameobjectpositioning.png
(10.9 kB)
Comment