Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Actually I have came here after searching from past 5-6 hours. Actually I am making a small game in which I have a camera and a gameobject. The Game Object is place in the center of the scene at 0,0,0 . My scene doesn't include anything but a skybox. I wanted to move my camera with gyro input, I got that working. My problem is that I want my object which is at 0,0,0 is to face camera always. The camera is controlled by gyro so the object should always remain infront of the camera. I have taken a script from wiki.unity3d and it seems to be somewhat working. Actually I want an offset for the transform.lookAt or if it's not possible I'll require some solution for it.

public class CameraFacing : MonoBehaviour
{
    public Camera m_Camera;

    void Update()
    {
        transform.LookAt((transform.position) + m_Camera.transform.rotation * Vector3.forward,
                m_Camera.transform.rotation * Vector3.up);
    }
}

Actually I have tried 3rd person and FPS shooter camera and Camera Follow script as well besides knowing it doesn't fit my need. As In most cases we want the camera to follow object. But in this case my input is through gyro of mobile device and I want the center object to always remain in front of camera.

share|improve this question
    
Have you tried making the GameObject a child of the camera? That way when the Camera moves the GameObject will automatically move with it – hobnob 26 mins ago
    
tried that but the gameobject doesn't remain in view of camera. As camera input is controlled through gyroscope. – Adnan Nazir 24 mins ago
    
Have you got the code you're using to move the camera? If the GameObject is a child then it should just move with the camera as it's transform is changed. As it's not, the problem might be the way you've implemented the movement. – hobnob 20 mins ago
    
ohhh thanks. I think I was overthinking because of that transform.LookAt which is not needed at all in my case. It was super simple. Sometimes we just need a clue. I am very thankful hobnob. Can you help how can I delete this question as it's super lame. – Adnan Nazir 4 mins ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.