Search Unity

orbit and move object

Discussion in 'iOS and tvOS' started by lesfundi, Jan 18, 2011.

  1. lesfundi

    lesfundi

    Joined:
    Jan 10, 2009
    Posts:
    628
    I have a scene with objects in centre of the scene and the camera is looking at the object.
    I looking for a script so I can move my ringer around on the iPad/iPhone and my objects orbit around.
    When I take my finger of the screen the object stays in same rotation when I click on the screen
    and start to drag the 3 objects orbit around centre.

    When I click and hold on a button on the screen I activated "move mode" than when I on click 3d with a finger
    I move the 3d object parallel to the camera.

    Anything out there?
     
  2. elveatles

    elveatles

    Joined:
    May 2, 2009
    Posts:
    147
  3. lesfundi

    lesfundi

    Joined:
    Jan 10, 2009
    Posts:
    628
    this works for on the PC/MAC. HOw can I can this to work on the iPad?
    I want when I hold down a button, i can move around my object in this same manner

    Code (csharp):
    1. var mainCamera : Camera;
    2. private var isDragging : boolean = false;
    3. private var distance : float;
    4.  
    5. function Start(){
    6.    mainCamera = Camera.main;
    7. }
    8.  
    9. function Update () {
    10.    if(!Input.GetKey("m")) isDragging = false;
    11.    
    12.    if(isDragging){
    13.       var ray = mainCamera.ScreenPointToRay(Input.mousePosition);
    14.       transform.position = ray.GetPoint(distance);
    15.    }
    16. }
    17.  
    18. function OnMouseDown(){
    19.    isDragging = true;
    20.    distance = Vector3.Distance(transform.position, mainCamera.transform.position);
    21. }
    22.  
    23. function OnMouseUp(){
    24.    isDragging = false;
    25. }
    26. }
     
    Last edited: Jan 19, 2011
  4. andeeeee

    andeeeee

    Joined:
    Jul 19, 2005
    Posts:
    8,768
    For the orbiting, you might be able to use the Mouse Orbit camera script that comes with Unity (or else adapt it a bit). There is a code example in this thread that shows how to drag an object in a plane parallel to the camera.
     
  5. lesfundi

    lesfundi

    Joined:
    Jan 10, 2009
    Posts:
    628
    Last edited: Jan 19, 2011