Search Unity

How to pan the view of a gameObject instead of the camera?

Discussion in 'Scripting' started by Exnihilon, Aug 29, 2014.

  1. Exnihilon

    Exnihilon

    Joined:
    Mar 2, 2014
    Posts:
    158
    Greetings to all. I'm having a hard time on this matter of panning a view of a gameObject. I'm new to Unity3d and scripting and I'm trying to develop an AR (Augmented Reality) application for Android.

    At one scene, I need to have a gameObject (e.g. a model of a floor), from the normal top down view, rendered to a "pseudo" iso view, inclined to 45 degrees. As the gameObject is inclined, I need to have a panning function on its view, utilizing four (4) buttons (for left, right, forward(or up), backward(or down)).

    The problem is that, I cannot use any of the known panning script snippets around the forum, as the AR camera has to be static in the scene.

    Need to mention that, I need the panning function to be active only at the isometric view, (which I'm already compute with another script), not on top down view. So there must be no problem with the inclination of the axes of the gameObject, right?

    Following, is two mockup images of the states the gameObject (model floor) is rendered and the script code (from Unity reference), that I'm currently using, which is not very much functional for my needs.

    TopDown.png

    Iso45.png

    Here is the code, for left movement of the gameObject (I use the same with a change in -, +speed values, for the other movements), but I get it only move up, down, not forth, backwards:

    Code (CSharp):
    1.  
    2. #pragma strict
    3.  
    4. // The target gameObject.
    5.     var target: Transform;
    6.    
    7.     // Speed in units per sec.
    8.     var speedLeft: float = -10;
    9.    
    10.     private static var isPanLeft = false;
    11.  
    12.  
    13.     function FixedUpdate()
    14.     {
    15.     if(isPanLeft == true)
    16.     {
    17.         // The step size is equal to speed times frame time.
    18.         var step = speedLeft * Time.deltaTime;
    19.        
    20.         // Move model position a step closer to the target.
    21.         transform.position = Vector3.MoveTowards(transform.position, target.position, step);
    22.     }
    23.     }
    24.    
    25.     static function doPanLeft()
    26.     {
    27.         isPanLeft = !isPanLeft;
    28.     }
    Can someone be kind enough to take a look at this post, and make a suggestion on how this functionality can be coded the easiest way, as I'm a newbie? Furthermore, If a sample code or a tutorial can be provided, it would be great, as I can learn from this, a lot. Thank you all in advance for your time and answers.
     
  2. Polymorphik

    Polymorphik

    Joined:
    Jul 25, 2014
    Posts:
    599
    Why can't you pan the camera? If you move the game object gravity will have an effect on it...if this is what you are going for then all you need to do is parent everything to the main object call it "Game Board" and rotate that.
     
  3. Exnihilon

    Exnihilon

    Joined:
    Mar 2, 2014
    Posts:
    158
    Hello @Polymorphik. As I've mentioned above, the camera has an AR script that renders the gameObject, in a static manner. Whatever script I've tried of panning the camera, I lose that static functionality, which is essential. So i need to move the gameObject instead, having the camera constant. Any tip on moving left - right (on X axis), forward - backwards (on Z axis)?
     
  4. smitchell

    smitchell

    Joined:
    Mar 12, 2012
    Posts:
    702
    your images are way to small to see by the way.
     
  5. Exnihilon

    Exnihilon

    Joined:
    Mar 2, 2014
    Posts:
    158
    Well @smitchell, those images are nothing more, than a schematic describing the functionality of moving the gameObject on X and Z axis as it is in isometric view state.
     
  6. Polymorphik

    Polymorphik

    Joined:
    Jul 25, 2014
    Posts:
    599
    Is gravity and issue?
     
  7. Exnihilon

    Exnihilon

    Joined:
    Mar 2, 2014
    Posts:
    158
    Gravity @Polymorphik is not an issue, as there is no rigidbody attached on gameObject.